mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 08:58:41 +00:00
彻底修复content莫名断开链接,导致devtool找不到游戏的bug
This commit is contained in:
parent
81d4beaed8
commit
6cb3869a0c
@ -20,6 +20,11 @@ export class TabInfo {
|
|||||||
let portContent: Content = new Content(tab, port, this);
|
let portContent: Content = new Content(tab, port, this);
|
||||||
this.contentArray.push(portContent);
|
this.contentArray.push(portContent);
|
||||||
this.updateFrames();
|
this.updateFrames();
|
||||||
|
// 之前持有的链接会断开,content会重新发起链接,重新连上之后,如果只有一个人链接,需要设置using状态,否则devtools找不到content
|
||||||
|
if (this.contentArray.length === 1) {
|
||||||
|
const id = this.contentArray[0].frameID;
|
||||||
|
this.useFrame(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public removePort(item: Content) {
|
public removePort(item: Content) {
|
||||||
let index = this.contentArray.findIndex((el) => el === item);
|
let index = this.contentArray.findIndex((el) => el === item);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// content.js 和原始界面共享DOM,具有操作dom的能力
|
// content.js 和原始界面共享DOM,具有操作dom的能力
|
||||||
// 但是不共享js,要想访问页面js,只能通过注入的方式
|
// 但是不共享js,要想访问页面js,只能通过注入的方式
|
||||||
import { ChromeConst } from "cc-plugin/src/chrome/const";
|
import { ChromeConst } from "cc-plugin/src/chrome/const";
|
||||||
import { debugLog, Msg, Page, PluginEvent } from "../../core/types";
|
import { debugLog, Page, PluginEvent } from "../../core/types";
|
||||||
import { ga } from "../../ga";
|
import { ga } from "../../ga";
|
||||||
import { GA_EventName } from "../../ga/type";
|
import { GA_EventName } from "../../ga/type";
|
||||||
import { DocumentEvent, GoogleAnalyticsData } from "../const";
|
import { DocumentEvent, GoogleAnalyticsData } from "../const";
|
||||||
@ -65,21 +65,26 @@ document.addEventListener(DocumentEvent.Inject2Content, (event: CustomEvent) =>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// #region 和background通讯
|
// #region 和background通讯
|
||||||
let connect: chrome.runtime.Port = chrome.runtime.connect({ name: Page.Content });
|
let connect: chrome.runtime.Port = null;
|
||||||
connect.onDisconnect.addListener(() => {
|
function doConnect() {
|
||||||
debugLog && console.log(...terminal.disconnect(""));
|
connect = chrome.runtime.connect({ name: Page.Content });
|
||||||
connect = null;
|
connect.onDisconnect.addListener(() => {
|
||||||
});
|
debugLog && console.log(...terminal.disconnect(""));
|
||||||
connect.onMessage.addListener((data: PluginEvent, sender: chrome.runtime.Port) => {
|
connect = null;
|
||||||
const event = PluginEvent.create(data);
|
doConnect();
|
||||||
if (event.valid && event.check(Page.Background, Page.Content)) {
|
});
|
||||||
debugLog && console.log(...terminal.chunkMessage(event.toChunk()));
|
connect.onMessage.addListener((data: PluginEvent, sender: chrome.runtime.Port) => {
|
||||||
event.reset(Page.Content, Page.Inject);
|
const event = PluginEvent.create(data);
|
||||||
const e = new CustomEvent(DocumentEvent.Content2Inject, { detail: event });
|
if (event.valid && event.check(Page.Background, Page.Content)) {
|
||||||
debugLog && console.log(...terminal.chunkSend(event.toChunk()));
|
debugLog && console.log(...terminal.chunkMessage(event.toChunk()));
|
||||||
document.dispatchEvent(e);
|
event.reset(Page.Content, Page.Inject);
|
||||||
} else {
|
const e = new CustomEvent(DocumentEvent.Content2Inject, { detail: event });
|
||||||
throw new Error(`invalid data: ${data}`);
|
debugLog && console.log(...terminal.chunkSend(event.toChunk()));
|
||||||
}
|
document.dispatchEvent(e);
|
||||||
});
|
} else {
|
||||||
|
throw new Error(`invalid data: ${data}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
doConnect();
|
||||||
injectScript(ChromeConst.script.inject);
|
injectScript(ChromeConst.script.inject);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user