devtools界面和content.js进行交互

This commit is contained in:
许彦峰
2019-03-16 19:18:29 +08:00
parent a8a26154f8
commit f00ae2cf90
5 changed files with 45 additions and 26 deletions

View File

@@ -43,27 +43,25 @@
}
},
created() {
debugger
let backgroundPageConnection = chrome.runtime.connect({
name: btoa("for" + String(chrome.devtools.inspectedWindow.tabId))
});
backgroundPageConnection.onMessage.addListener(function (message) {
if (message !== null) {
// chrome.devtools.inspectedWindow.tabId
let conn = chrome.runtime.connect({name: "devtools"});
conn.onMessage.addListener(function (data, sender) {
if (data !== null) {
let msgType = {
nodeInfo: 2,//节点信息
nodeListInfo: 1,// 节点列表信息
notSupport: 0,// 不支持的游戏
};
if (message.type === msgType.nodeListInfo) {// 游戏节点
if (data.type === msgType.nodeListInfo) {// 游戏节点
this.isShowDebug = true;
// let str = JSON.stringify(message.msg);
// console.log("onMessage: " + str);
this._updateView(message.msg);
} else if (message.type === msgType.notSupport) {// 不支持调试
this._updateView(data.msg);
} else if (data.type === msgType.notSupport) {// 不支持调试
this.isShowDebug = false;
} else if (message.type === msgType.nodeInfo) {
} else if (data.type === msgType.nodeInfo) {
this.isShowDebug = true;
this.treeItemData = message.msg;
this.treeItemData = data.msg;
}
}
}.bind(this));
@@ -178,6 +176,10 @@
onBtnClickUpdatePage() {
debugger
let injectCode =`console.log(window.ccinspector);window.ccinspector.stop=!window.ccinspector.stop;`;
chrome.devtools.inspectedWindow.eval(injectCode);
return;
let code = this._getInjectScriptString();
chrome.devtools.inspectedWindow.eval(code, function () {
console.log("刷新成功!");