简体   繁体   English

Chrome 扩展调试器未定义

[英]Chrome extension debugger undefined

I'd like to simulate a trusted click event for a chrome extension using the debugger api seen here .我想使用此处看到的调试器 api 模拟 chrome 扩展程序的可信点击事件。

However, chrome.debugger is undefined.但是, chrome.debugger 是未定义的。

chrome.debugger.attach(target, "1.2", function() {
    chrome.debugger.sendCommand(target, "Input.dispatchMouseEvent", arguments)
})

manifest.json清单文件

"permissions": [
    "debugger", "storage"
 ]

Am I missing something?我错过了什么吗? How can I effectively call chrome.debugger?如何有效地调用 chrome.debugger? When I look at the permissions in chrome://extensions it shows that I have "Access the page debugger backend"当我查看 chrome://extensions 中的权限时,它显示我有“访问页面调试器后端”

You need to attach the debugger interface to the tab via a background script:您需要通过后台脚本将调试器界面附加到选项卡:

let tabId = tab.id;
let debuggeeId = { tabId };
chrome.debugger.attach(debuggeeId, version, onAttach.bind(null, debuggeeId));

And then进而

const onDebuggerEnabled = (debuggeeId) => {
  debuggerEnabled = true
}

const onAttach = (debuggeeId) => {
chrome.debugger.sendCommand(
    debuggeeId, "Debugger.enable", {},
    onDebuggerEnabled.bind(null, debuggeeId));
}

Then you can use message passing to send requests to the background script from the content script: https://developer.chrome.com/extensions/messaging然后你可以使用消息传递从内容脚本向后台脚本发送请求: https : //developer.chrome.com/extensions/messaging

And

if (debuggerEnabled) {
chrome.debugger.sendCommand(debuggeeId, "Input.dispatchMouseEvent", { type: "mousePressed", x: xC, y: yC, button: "left" }, function (e) { console.log('mousedown', e) });

chrome.debugger.sendCommand(debuggeeId, "Input.dispatchMouseEvent", { type: "mouseReleased", x: xC, y: yC, button: "left" }, function (e) { console.log('mouseup', e) });
} 
// xC, yC are your coordinates

This is a working example: https://github.com/Sentero-esp12/IsTrusted-event-Debugger-API这是一个工作示例: https : //github.com/Sentero-esp12/IsTrusted-event-Debugger-API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM