【发布时间】:2017-05-04 12:37:18
【问题描述】:
我需要使用 chrome 扩展在 facebook 状态字段中使用给定的字符代码触发按键事件。有没有正确的方法来做到这一点。
我尝试使用以下代码。但似乎不起作用。
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 });
});
}
});
【问题讨论】:
-
运气好吗?
标签: javascript jquery google-chrome-extension dom-events