mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-19 08:28:41 +00:00
debug相关功能的学习代码
This commit is contained in:
parent
5bdaf105a1
commit
243d786666
@ -12,6 +12,86 @@ chrome.runtime.onConnect.addListener((port) => {
|
|||||||
chrome.runtime.onMessage.addListener((message) => {
|
chrome.runtime.onMessage.addListener((message) => {
|
||||||
console.log("runtime onMessage: ", message)
|
console.log("runtime onMessage: ", message)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
chrome.debugger.onEvent.addListener((source, method, params) => {
|
||||||
|
// console.log("debugger onEvent: ", source, method, params)
|
||||||
|
})
|
||||||
|
chrome.action.onClicked.addListener((tab) => {
|
||||||
|
debugger
|
||||||
|
// 使用devtools协议链接到页面
|
||||||
|
chrome.debugger.attach({ tabId: tab.id }, "1.0", () => {
|
||||||
|
chrome.debugger.sendCommand({ tabId: tab.id }, "Debugger.enable", {}, () => { });
|
||||||
|
return;
|
||||||
|
debugger;
|
||||||
|
// 启动调试器
|
||||||
|
chrome.debugger.sendCommand({ tabId: tab.id }, "Debugger.enable", {}, () => {
|
||||||
|
debugger;
|
||||||
|
// chrome.debugger.sendCommand({ tabId: tab.id }, "Debugger.getScriptSource", (scripts) => {
|
||||||
|
// console.log(scripts);
|
||||||
|
// debugger
|
||||||
|
// })
|
||||||
|
chrome.debugger.sendCommand(
|
||||||
|
{ tabId: tab.id, },
|
||||||
|
"Runtime.evaluate",
|
||||||
|
{ expression: "window.abc=()=>{console.log(1)}" },
|
||||||
|
(result) => {
|
||||||
|
debugger
|
||||||
|
if (result && result.result && result.result.objectId) {
|
||||||
|
console.log(result.result);
|
||||||
|
|
||||||
|
chrome.debugger.sendCommand(
|
||||||
|
{
|
||||||
|
tabId: tab.id,
|
||||||
|
method: "Debugger.searchInContentScripts",
|
||||||
|
params: {
|
||||||
|
query: "abc",
|
||||||
|
}
|
||||||
|
}, (result) => {
|
||||||
|
debugger
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
// 获取func
|
||||||
|
chrome.debugger.sendCommand(
|
||||||
|
{
|
||||||
|
tabId: tab.id,
|
||||||
|
method: "Debugger.searchInContentScripts",
|
||||||
|
params: {
|
||||||
|
query: "window.abc",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Debugger.searchInContentScripts",
|
||||||
|
{ functionId: result.result.objectId },
|
||||||
|
(location) => {
|
||||||
|
debugger
|
||||||
|
console.log(location);
|
||||||
|
if (location) {
|
||||||
|
// 调整到函数
|
||||||
|
chrome.debugger.sendCommand(
|
||||||
|
{ tabId: tab.id, },
|
||||||
|
"Debugger.setBreakpoint",
|
||||||
|
{
|
||||||
|
location: location.locations[0],
|
||||||
|
},
|
||||||
|
(brk) => {
|
||||||
|
debugger
|
||||||
|
console.log(brk);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
// chrome.tabs.onConnect.addListener((port) => {
|
// chrome.tabs.onConnect.addListener((port) => {
|
||||||
// console.log("tabs onConnect: ", port)
|
// console.log("tabs onConnect: ", port)
|
||||||
// port.onMessage.addListener((message) => {
|
// port.onMessage.addListener((message) => {
|
||||||
|
@ -8,5 +8,6 @@
|
|||||||
devtools
|
devtools
|
||||||
<button id="send2bg">send to background</button>
|
<button id="send2bg">send to background</button>
|
||||||
<div id="text"></div>
|
<div id="text"></div>
|
||||||
|
<img src="https://fanyi-cdn.cdn.bcebos.com/static/cat/asset/logo.2481f256.png" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -31,6 +31,10 @@ if (send2bg) {
|
|||||||
console.log('href: ', window.location.href);
|
console.log('href: ', window.location.href);
|
||||||
console.log(chrome.devtools);
|
console.log(chrome.devtools);
|
||||||
console.log(chrome.devtools.inspectedWindow.tabId);
|
console.log(chrome.devtools.inspectedWindow.tabId);
|
||||||
|
chrome.devtools.panels.setOpenResourceHandler((res) => {
|
||||||
|
debugger;
|
||||||
|
console.log(res);
|
||||||
|
})
|
||||||
chrome.devtools.panels.create("Hello World", "icon.png", "devtools.html", (panel) => {
|
chrome.devtools.panels.create("Hello World", "icon.png", "devtools.html", (panel) => {
|
||||||
console.log("panel created");
|
console.log("panel created");
|
||||||
panel.onShown.addListener((win, b) => {
|
panel.onShown.addListener((win, b) => {
|
||||||
@ -47,8 +51,16 @@ chrome.devtools.panels.create("Hello World", "icon.png", "devtools.html", (panel
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
// panel.createStatusBarButton({})
|
||||||
|
// panel.show();
|
||||||
|
|
||||||
panel.onHidden.addListener((a, b) => {
|
panel.onHidden.addListener((a, b) => {
|
||||||
console.log("panel hidden", a, b);
|
console.log("panel hidden", a, b);
|
||||||
|
// setTimeout(() => {
|
||||||
|
// debugger;
|
||||||
|
|
||||||
|
// panel.show();
|
||||||
|
// }, 3 * 1000);
|
||||||
});
|
});
|
||||||
panel.onSearch.addListener((query) => {
|
panel.onSearch.addListener((query) => {
|
||||||
console.log("panel search", query);
|
console.log("panel search", query);
|
||||||
|
@ -23,10 +23,13 @@
|
|||||||
},
|
},
|
||||||
"name": "helloworld",
|
"name": "helloworld",
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
|
"permissions": [
|
||||||
|
"tabs",
|
||||||
|
"debugger"
|
||||||
|
],
|
||||||
"host_permissions": [
|
"host_permissions": [
|
||||||
"wss://*/*",
|
"wss://*/*",
|
||||||
"ws://*/*",
|
"ws://*/*",
|
||||||
"activeTab",
|
|
||||||
"<all_urls>",
|
"<all_urls>",
|
||||||
"*://*/*",
|
"*://*/*",
|
||||||
"tabs",
|
"tabs",
|
||||||
@ -45,7 +48,6 @@
|
|||||||
"notifications"
|
"notifications"
|
||||||
],
|
],
|
||||||
"action": {
|
"action": {
|
||||||
"default_popup": "popup.html",
|
|
||||||
"default_icon": {
|
"default_icon": {
|
||||||
"48": "./icons/48.png"
|
"48": "./icons/48.png"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user