如何在Chrome扩展程序上模拟密钥新闻事件



我需要使用Chrome Extension在Facebook状态字段中使用给定的CHAR代码触发关键事件。有正确的方法吗?

我尝试了以下代码。但似乎不起作用。

chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
    if(message.pressEnter){
        chrome.tabs.query({active: true}, function(tabs) {
            chrome.debugger.attach({ tabId: tabs[0].id }, "1.0");
            chrome.debugger.sendCommand({ tabId: tabs[0].id }, 'Input.dispatchKeyEvent', { type: 'keypress', windowsVirtualKeyCode:13, nativeVirtualKeyCode : 13, macCharCode: 13  });
            chrome.debugger.sendCommand({ tabId: tabs[0].id }, 'Input.dispatchKeyEvent', { type: 'keyDown', windowsVirtualKeyCode:13, nativeVirtualKeyCode : 13, macCharCode: 13  });
            chrome.debugger.detach({ tabId: tabs[0].id });
        });
    }
});

当您使用Chrome Debugger API的输入时,disPatchKeyevent,目标元素是什么元素?定期派遣需要指定目标元素。

此外,使用普通JavaScript调度API派遣的事件不信任,因此它们不会触发默认行为。例如。使用JavaScript将字母A派遣到文本输入对规格无能为力。

因此,首先检查要派遣的事件是否受到信任,然后查找其目标的元素。

最新更新