[英]Chrome extension debugger undefined
我想使用此处看到的调试器 api 模拟 chrome 扩展程序的可信点击事件。
但是, chrome.debugger 是未定义的。
chrome.debugger.attach(target, "1.2", function() {
chrome.debugger.sendCommand(target, "Input.dispatchMouseEvent", arguments)
})
清单文件
"permissions": [
"debugger", "storage"
]
我错过了什么吗? 如何有效地调用 chrome.debugger? 当我查看 chrome://extensions 中的权限时,它显示我有“访问页面调试器后端”
您需要通过后台脚本将调试器界面附加到选项卡:
let tabId = tab.id;
let debuggeeId = { tabId };
chrome.debugger.attach(debuggeeId, version, onAttach.bind(null, debuggeeId));
进而
const onDebuggerEnabled = (debuggeeId) => {
debuggerEnabled = true
}
const onAttach = (debuggeeId) => {
chrome.debugger.sendCommand(
debuggeeId, "Debugger.enable", {},
onDebuggerEnabled.bind(null, debuggeeId));
}
然后你可以使用消息传递从内容脚本向后台脚本发送请求: https : //developer.chrome.com/extensions/messaging
和
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
这是一个工作示例: https : //github.com/Sentero-esp12/IsTrusted-event-Debugger-API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.