mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 08:58:41 +00:00
no message
This commit is contained in:
parent
ffc404b67a
commit
c293754259
@ -2,11 +2,12 @@ let PluginMsg = require("../core/plugin-msg");
|
|||||||
// 链接池子
|
// 链接池子
|
||||||
let ConnPool = {
|
let ConnPool = {
|
||||||
Devtools: null,
|
Devtools: null,
|
||||||
|
DevtoolsPanel: null,
|
||||||
|
Content: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
function shortConnectionLink(request, sender, sendResponse) {
|
function shortConnectionLink(request, sender, sendResponse) {
|
||||||
console.log(`%c[短连接|id:${sender.id}|url:${sender.url}]\n${JSON.stringify(request)}`, 'background:#aaa;color:#BD4E19')
|
// console.log(`%c[短连接|id:${sender.id}|url:${sender.url}]\n${JSON.stringify(request)}`, 'background:#aaa;color:#BD4E19')
|
||||||
sendResponse && sendResponse(request);
|
sendResponse && sendResponse(request);
|
||||||
if (request.msg === PluginMsg.Msg.Support ||
|
if (request.msg === PluginMsg.Msg.Support ||
|
||||||
request.msg === PluginMsg.Msg.ListInfo ||
|
request.msg === PluginMsg.Msg.ListInfo ||
|
||||||
@ -19,6 +20,11 @@ function shortConnectionLink(request, sender, sendResponse) {
|
|||||||
function longConnectionLink(data, sender) {
|
function longConnectionLink(data, sender) {
|
||||||
console.log(`%c[长连接:${sender.name}]\n${JSON.stringify(data)}`, 'background:#aaa;color:#bada55')
|
console.log(`%c[长连接:${sender.name}]\n${JSON.stringify(data)}`, 'background:#aaa;color:#bada55')
|
||||||
sender.postMessage(data);
|
sender.postMessage(data);
|
||||||
|
if (data.msg === PluginMsg.Msg.UrlChange) {
|
||||||
|
if (sender.name === PluginMsg.Page.DevToolsPanel) {
|
||||||
|
ConnPool.Content && ConnPool.Content.postMessage({msg: PluginMsg.Msg.UrlChange, data: {}})
|
||||||
|
}
|
||||||
|
}
|
||||||
// chrome.tabs.executeScript(message.tabId, {code: message.content});
|
// chrome.tabs.executeScript(message.tabId, {code: message.content});
|
||||||
// port.postMessage(message);
|
// port.postMessage(message);
|
||||||
}
|
}
|
||||||
@ -32,12 +38,20 @@ chrome.runtime.onConnect.addListener(function (port) {
|
|||||||
port.onMessage.removeListener(longConnectionLink);
|
port.onMessage.removeListener(longConnectionLink);
|
||||||
if (port.name === PluginMsg.Page.Devtools) {
|
if (port.name === PluginMsg.Page.Devtools) {
|
||||||
ConnPool.Devtools = null;
|
ConnPool.Devtools = null;
|
||||||
|
} else if (port.name === PluginMsg.Page.Content) {
|
||||||
|
ConnPool.Content = null;
|
||||||
|
} else if (port.name === PluginMsg.Page.DevToolsPanel) {
|
||||||
|
ConnPool.DevtoolsPanel = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 缓存
|
// 缓存
|
||||||
if (port.name === PluginMsg.Page.Devtools) {
|
if (port.name === PluginMsg.Page.Devtools) {
|
||||||
ConnPool.Devtools = port;
|
ConnPool.Devtools = port;
|
||||||
|
} else if (port.name === PluginMsg.Page.Content) {
|
||||||
|
ConnPool.Content = port;
|
||||||
|
} else if (port.name === PluginMsg.Page.DevToolsPanel) {
|
||||||
|
ConnPool.DevtoolsPanel = port;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -45,6 +59,12 @@ chrome.runtime.onConnect.addListener(function (port) {
|
|||||||
// [短连接] 监听来自content.js发来的事件
|
// [短连接] 监听来自content.js发来的事件
|
||||||
chrome.runtime.onMessage.addListener(shortConnectionLink);
|
chrome.runtime.onMessage.addListener(shortConnectionLink);
|
||||||
|
|
||||||
|
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||||
|
if (changeInfo.status === "complete") {
|
||||||
|
// 加载新的url
|
||||||
|
ConnPool.Content.postMessage({msg: PluginMsg.Msg.UrlChange, data: {url: tab.favIconUrl}});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
function createPluginMenus() {
|
function createPluginMenus() {
|
||||||
// 右键菜单
|
// 右键菜单
|
||||||
|
@ -19,10 +19,11 @@ function injectScriptToPage(url) {
|
|||||||
injectScriptToPage("js/inject.js");
|
injectScriptToPage("js/inject.js");
|
||||||
|
|
||||||
// 和background.js保持长连接通讯
|
// 和background.js保持长连接通讯
|
||||||
let conn = chrome.runtime.connect({name: "connect.js"})
|
let conn = chrome.runtime.connect({name: PluginMsg.Page.Content})
|
||||||
// conn.postMessage('test');
|
// conn.postMessage('test');
|
||||||
conn.onMessage.addListener(function (data) {
|
conn.onMessage.addListener(function (data) {
|
||||||
console.log(data)
|
// 将background.js的消息返回到injection.js
|
||||||
|
window.postMessage(data, "*");
|
||||||
})
|
})
|
||||||
// 接受来自inject.js的消息数据,然后中转到background.js
|
// 接受来自inject.js的消息数据,然后中转到background.js
|
||||||
window.addEventListener('message', function (event) {
|
window.addEventListener('message', function (event) {
|
||||||
|
@ -16,13 +16,17 @@ let cc_inspector = {
|
|||||||
},
|
},
|
||||||
init() {
|
init() {
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
this.checkIsGamePage(true);
|
// this.checkIsGamePage(true);
|
||||||
// if (this.stop) {
|
// if (this.stop) {
|
||||||
// } else {
|
// } else {
|
||||||
// }
|
// }
|
||||||
}.bind(this), 1000);
|
}.bind(this), 1000);
|
||||||
// 注册cc_after_render事件
|
// 注册cc_after_render事件
|
||||||
|
window.addEventListener('message', function (event) {
|
||||||
|
if (event.data.msg === PluginMsg.Msg.UrlChange) {
|
||||||
|
this.checkIsGamePage(true);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
updateTreeInfo() {
|
updateTreeInfo() {
|
||||||
let isCocosCreatorGame = this.checkIsGamePage(true);
|
let isCocosCreatorGame = this.checkIsGamePage(true);
|
||||||
@ -90,26 +94,26 @@ let cc_inspector = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
pluginSetNodeColor(uuid, colorHex) {
|
pluginSetNodeColor(uuid, colorHex) {
|
||||||
let node = window.inspectorGameMemoryStorage[uuid];
|
let node = this.inspectorGameMemoryStorage[uuid];
|
||||||
if (node) {
|
if (node) {
|
||||||
node.color = cc.hexToColor(colorHex);
|
node.color = cc.hexToColor(colorHex);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pluginSetNodeRotation(uuid, rotation) {
|
pluginSetNodeRotation(uuid, rotation) {
|
||||||
let node = window.inspectorGameMemoryStorage[uuid];
|
let node = this.inspectorGameMemoryStorage[uuid];
|
||||||
if (node) {
|
if (node) {
|
||||||
node.rotation = rotation;
|
node.rotation = rotation;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pluginSetNodePosition(uuid, x, y) {
|
pluginSetNodePosition(uuid, x, y) {
|
||||||
let node = window.inspectorGameMemoryStorage[uuid];
|
let node = this.inspectorGameMemoryStorage[uuid];
|
||||||
if (node) {
|
if (node) {
|
||||||
node.x = x;
|
node.x = x;
|
||||||
node.y = y;
|
node.y = y;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pluginSetNodeSize(uuid, width, height) {
|
pluginSetNodeSize(uuid, width, height) {
|
||||||
let node = window.inspectorGameMemoryStorage[uuid];
|
let node = this.inspectorGameMemoryStorage[uuid];
|
||||||
if (node) {
|
if (node) {
|
||||||
node.width = width;
|
node.width = width;
|
||||||
node.height = height;
|
node.height = height;
|
||||||
@ -117,7 +121,7 @@ let cc_inspector = {
|
|||||||
},
|
},
|
||||||
// 设置节点是否可视
|
// 设置节点是否可视
|
||||||
pluginSetNodeActive(uuid, isActive) {
|
pluginSetNodeActive(uuid, isActive) {
|
||||||
let node = window.inspectorGameMemoryStorage[uuid];
|
let node = this.inspectorGameMemoryStorage[uuid];
|
||||||
if (node) {
|
if (node) {
|
||||||
if (isActive === 1) {
|
if (isActive === 1) {
|
||||||
node.active = true;
|
node.active = true;
|
||||||
@ -188,6 +192,21 @@ let cc_inspector = {
|
|||||||
sendMsgToDevTools(msg, data) {
|
sendMsgToDevTools(msg, data) {
|
||||||
window.postMessage({msg: msg, data: data}, "*");
|
window.postMessage({msg: msg, data: data}, "*");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onMemoryInfo() {
|
||||||
|
this.sendMsgToDevTools(PluginMsg.Msg.MemoryInfo, {
|
||||||
|
performance: {
|
||||||
|
jsHeapSizeLimit: window.performance.memory.jsHeapSizeLimit,
|
||||||
|
totalJSHeapSize: window.performance.memory.totalJSHeapSize,
|
||||||
|
usedJSHeapSize: window.performance.memory.usedJSHeapSize,
|
||||||
|
},
|
||||||
|
console: {
|
||||||
|
jsHeapSizeLimit: console.memory.jsHeapSizeLimit,
|
||||||
|
totalJSHeapSize: console.memory.totalJSHeapSize,
|
||||||
|
usedJSHeapSize: console.memory.usedJSHeapSize,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.ccinspector = window.ccinspector || cc_inspector;
|
window.ccinspector = window.ccinspector || cc_inspector;
|
||||||
window.ccinspector.init && window.ccinspector.init();// 执行初始化函数
|
window.ccinspector.init && window.ccinspector.init();// 执行初始化函数
|
||||||
|
@ -2,6 +2,7 @@ module.exports = {
|
|||||||
Page: {
|
Page: {
|
||||||
Inject: "inject.js",
|
Inject: "inject.js",
|
||||||
Devtools: "devtools.js",
|
Devtools: "devtools.js",
|
||||||
|
DevToolsPanel:"DevToolsPanel",
|
||||||
Content: "content.js",
|
Content: "content.js",
|
||||||
Popup: "popup.js",
|
Popup: "popup.js",
|
||||||
Options: "options.js",
|
Options: "options.js",
|
||||||
@ -10,5 +11,7 @@ module.exports = {
|
|||||||
NodeInfo: "node_info",// 具体的节点信息
|
NodeInfo: "node_info",// 具体的节点信息
|
||||||
ListInfo: "list_info",// 节点树信息
|
ListInfo: "list_info",// 节点树信息
|
||||||
Support: "game_support",// 游戏支持信息
|
Support: "game_support",// 游戏支持信息
|
||||||
|
MemoryInfo:"memory_info",//
|
||||||
|
UrlChange:"url_change",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
const PluginMsg = require("../core/plugin-msg");
|
||||||
// 对应的是Elements面板的边栏
|
// 对应的是Elements面板的边栏
|
||||||
chrome.devtools.panels.elements.createSidebarPane('Cocos', function (sidebar) {
|
chrome.devtools.panels.elements.createSidebarPane('Cocos', function (sidebar) {
|
||||||
sidebar.setObject({some_data: "some data to show!"});
|
sidebar.setObject({some_data: "some data to show!"});
|
||||||
@ -5,8 +6,15 @@ chrome.devtools.panels.elements.createSidebarPane('Cocos', function (sidebar) {
|
|||||||
// 创建devtools-panel
|
// 创建devtools-panel
|
||||||
chrome.devtools.panels.create("Cocos", "icon/icon48.png", "pages/devtools_panel.html", function (panel) {
|
chrome.devtools.panels.create("Cocos", "icon/icon48.png", "pages/devtools_panel.html", function (panel) {
|
||||||
console.log("[CC-Inspector] Dev Panel Created!");
|
console.log("[CC-Inspector] Dev Panel Created!");
|
||||||
|
let conn = chrome.runtime.connect({name: PluginMsg.Page.DevToolsPanel});
|
||||||
|
conn.onMessage.addListener(function (event, sender) {
|
||||||
|
debugger
|
||||||
|
});
|
||||||
|
|
||||||
panel.onShown.addListener(function (window) {
|
panel.onShown.addListener(function (window) {
|
||||||
console.log("panel show");
|
console.log("panel show");
|
||||||
|
debugger
|
||||||
|
conn.postMessage({msg: PluginMsg.Msg.UrlChange, data: {}})
|
||||||
});
|
});
|
||||||
panel.onHidden.addListener(function (window) {
|
panel.onHidden.addListener(function (window) {
|
||||||
console.log("panel hide");
|
console.log("panel hide");
|
||||||
|
@ -129,17 +129,14 @@
|
|||||||
</ui-prop>
|
</ui-prop>
|
||||||
<!--颜色-->
|
<!--颜色-->
|
||||||
<ui-prop name="color">
|
<ui-prop name="color">
|
||||||
<div style="float: left;width: 100%;height: 100%;">
|
<div style="display: flex;flex-direction: row;justify-content: center;">
|
||||||
<div style="float: left;width: 50%; height: 100%;">
|
<div style="display: flex;flex:1;">
|
||||||
<el-color-picker v-model="itemData.color" size="mini"
|
|
||||||
style="margin: 0;display: flex;align-items: center;flex-wrap: wrap;"
|
|
||||||
@change="changeColor"></el-color-picker>
|
|
||||||
</div>
|
|
||||||
<div style="float: left;width: 50%;">
|
|
||||||
<span>{{itemData.color}}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<el-color-picker v-model="itemData.color" size="mini" style="flex:1;margin: 0;" @change="changeColor"></el-color-picker>
|
||||||
|
</div>
|
||||||
|
<span style="width: 60px;">{{itemData.color}}</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
</ui-prop>
|
</ui-prop>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -177,7 +174,7 @@
|
|||||||
// console.log("change changePositionX:" + this.itemData.x);
|
// console.log("change changePositionX:" + this.itemData.x);
|
||||||
// console.log("change changePositionY:" + this.itemData.y);
|
// console.log("change changePositionY:" + this.itemData.y);
|
||||||
this._evalCode(
|
this._evalCode(
|
||||||
"window.pluginSetNodePosition(" +
|
"window.ccinspector.pluginSetNodePosition(" +
|
||||||
"'" + this.itemData.uuid + "'," +
|
"'" + this.itemData.uuid + "'," +
|
||||||
"'" + this.itemData.x + "'," +
|
"'" + this.itemData.x + "'," +
|
||||||
"'" + this.itemData.y + "'" +
|
"'" + this.itemData.y + "'" +
|
||||||
@ -188,7 +185,7 @@
|
|||||||
// console.log("change width:" + this.itemData.width);
|
// console.log("change width:" + this.itemData.width);
|
||||||
// console.log("change height:" + this.itemData.height);
|
// console.log("change height:" + this.itemData.height);
|
||||||
this._evalCode(
|
this._evalCode(
|
||||||
"window.pluginSetNodeSize(" +
|
"window.ccinspector.pluginSetNodeSize(" +
|
||||||
"'" + this.itemData.uuid + "'," +
|
"'" + this.itemData.uuid + "'," +
|
||||||
"'" + this.itemData.width + "'," +
|
"'" + this.itemData.width + "'," +
|
||||||
"'" + this.itemData.height + "'" +
|
"'" + this.itemData.height + "'" +
|
||||||
@ -198,7 +195,7 @@
|
|||||||
changeRotation() {
|
changeRotation() {
|
||||||
console.log("change rotation:" + this.itemData.rotation);
|
console.log("change rotation:" + this.itemData.rotation);
|
||||||
this._evalCode(
|
this._evalCode(
|
||||||
"window.pluginSetNodeRotation('" +
|
"window.ccinspector.pluginSetNodeRotation('" +
|
||||||
this.itemData.uuid + "','" +
|
this.itemData.uuid + "','" +
|
||||||
this.itemData.rotation + "')");
|
this.itemData.rotation + "')");
|
||||||
this._freshNode();
|
this._freshNode();
|
||||||
@ -207,7 +204,7 @@
|
|||||||
let color = this.itemData.color;
|
let color = this.itemData.color;
|
||||||
console.log("color:" + color);
|
console.log("color:" + color);
|
||||||
this._evalCode(
|
this._evalCode(
|
||||||
"window.pluginSetNodeColor('" +
|
"window.ccinspector.pluginSetNodeColor('" +
|
||||||
this.itemData.uuid + "','" +
|
this.itemData.uuid + "','" +
|
||||||
color + "');");
|
color + "');");
|
||||||
this._freshNode();
|
this._freshNode();
|
||||||
@ -215,7 +212,7 @@
|
|||||||
onBtnClickNodeHide() {
|
onBtnClickNodeHide() {
|
||||||
let uuid = this.itemData.uuid;
|
let uuid = this.itemData.uuid;
|
||||||
if (uuid !== undefined) {
|
if (uuid !== undefined) {
|
||||||
let code = "window.pluginSetNodeActive('" + uuid + "', 0);";
|
let code = "window.ccinspector.pluginSetNodeActive('" + uuid + "', 0);";
|
||||||
this._evalCode(code);
|
this._evalCode(code);
|
||||||
this._freshNode();
|
this._freshNode();
|
||||||
}
|
}
|
||||||
@ -223,14 +220,14 @@
|
|||||||
onBtnClickNodeShow() {
|
onBtnClickNodeShow() {
|
||||||
let uuid = this.itemData.uuid;
|
let uuid = this.itemData.uuid;
|
||||||
if (uuid !== undefined) {
|
if (uuid !== undefined) {
|
||||||
let code = "window.pluginSetNodeActive('" + uuid + "', 1);";
|
let code = "window.ccinspector.pluginSetNodeActive('" + uuid + "', 1);";
|
||||||
this._evalCode(code);
|
this._evalCode(code);
|
||||||
this._freshNode();
|
this._freshNode();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_freshNode() {
|
_freshNode() {
|
||||||
let uuid = this.itemData.uuid;
|
let uuid = this.itemData.uuid;
|
||||||
let code2 = "window.getNodeInfo('" + uuid + "')";
|
let code2 = "window.ccinspector.getNodeInfo('" + uuid + "')";
|
||||||
this._evalCode(code2);
|
this._evalCode(code2);
|
||||||
},
|
},
|
||||||
_evalCode(code) {
|
_evalCode(code) {
|
||||||
|
@ -4,7 +4,12 @@
|
|||||||
<div>
|
<div>
|
||||||
<el-button type="success" size="mini" @click="onBtnClickTest1">Test1</el-button>
|
<el-button type="success" size="mini" @click="onBtnClickTest1">Test1</el-button>
|
||||||
<el-button type="success" size="mini" @click="onBtnClickTest2">Test2</el-button>
|
<el-button type="success" size="mini" @click="onBtnClickTest2">Test2</el-button>
|
||||||
<el-button type="success" size="mini" @click="onBtnClickTest3">Test3</el-button>
|
<el-button type="success" size="mini" @click="onMemoryTest">内存测试</el-button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>JS堆栈限制: {{memory.performance.jsHeapSizeLimit}}</span>
|
||||||
|
<span>JS堆栈大小: {{memory.performance.totalJSHeapSize}}</span>
|
||||||
|
<span>JS堆栈使用: {{memory.performance.usedJSHeapSize}}</span>
|
||||||
</div>
|
</div>
|
||||||
<el-row style="display:flex; flex: 1;">
|
<el-row style="display:flex; flex: 1;">
|
||||||
<el-col :span="8">
|
<el-col :span="8">
|
||||||
@ -56,6 +61,10 @@
|
|||||||
label: 'label'
|
label: 'label'
|
||||||
},
|
},
|
||||||
watchEveryTime: false,// 实时监控节点树
|
watchEveryTime: false,// 实时监控节点树
|
||||||
|
memory: {
|
||||||
|
performance: {},
|
||||||
|
console: {},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@ -76,6 +85,8 @@
|
|||||||
} else if (eventMsg === PluginMsg.Msg.NodeInfo) {
|
} else if (eventMsg === PluginMsg.Msg.NodeInfo) {
|
||||||
this.isShowDebug = true;
|
this.isShowDebug = true;
|
||||||
this.treeItemData = eventData;
|
this.treeItemData = eventData;
|
||||||
|
} else if (eventMsg === PluginMsg.Msg.MemoryInfo) {
|
||||||
|
this.memory = eventData;
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
@ -202,8 +213,7 @@
|
|||||||
}`;
|
}`;
|
||||||
console.log(injectCode);
|
console.log(injectCode);
|
||||||
let ret = chrome.devtools.inspectedWindow.eval(injectCode, function (result, info) {
|
let ret = chrome.devtools.inspectedWindow.eval(injectCode, function (result, info) {
|
||||||
if (info.isException) {
|
if (info && info.isException) {
|
||||||
debugger
|
|
||||||
console.log(info.value)
|
console.log(info.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +244,9 @@
|
|||||||
// chrome.devtools.inspectedWindow.eval(`window.ccinspector.testMsg3()`)
|
// chrome.devtools.inspectedWindow.eval(`window.ccinspector.testMsg3()`)
|
||||||
let f = require("../../core/event-mgr");
|
let f = require("../../core/event-mgr");
|
||||||
console.log(f.id);
|
console.log(f.id);
|
||||||
|
},
|
||||||
|
onMemoryTest() {
|
||||||
|
this.evalInspectorFunction("onMemoryInfo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,12 @@ module.exports = {
|
|||||||
"http://*/*",
|
"http://*/*",
|
||||||
"https://*/*",
|
"https://*/*",
|
||||||
"*://*/*",
|
"*://*/*",
|
||||||
|
"audio",
|
||||||
"system.cpu",
|
"system.cpu",
|
||||||
|
"clipboardRead",
|
||||||
|
"clipboardWrite",
|
||||||
|
"system.memory",
|
||||||
|
"processes",// 这个权限只在chrome-dev版本都才有
|
||||||
"tabs",
|
"tabs",
|
||||||
"storage",
|
"storage",
|
||||||
"nativeMessaging",
|
"nativeMessaging",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user