我正在尝试调度一个 IsTrusted 事件来模拟用户单击屏幕上的某个位置。我正在通过 Chrome 扩展尝试这一点,尽管我运气不太好。控制台中没有错误,并且我的巨大屏幕按钮没有被点击。这是我的background.js:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var activeTab = tabs[0];
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "clickElement" ) {
chrome.debugger.attach({tabId:tab.id}, "1.2", function(debugg) {
chrome.debugger.sendCommand(
{tabId:tab.id}, "Debugger.enable", {},
function() {
chrome.debugger.sendCommand({tabId:tab.id}, "Input.dispatchMouseEvent",
{
type:"mousePressed",
x:parseFloat(request.x),
y:parseFloat(request.y)
})
})
})
}
}
);
chrome.tabs.sendMessage(activeTab.id, {"message": "runbot"});
});
});
Run Code Online (Sandbox Code Playgroud)
我content.js只是发送带有按钮坐标的 clickElement 消息。
有任何想法吗?