问题描述
我发现 event.initKeyboardEvent()是一个用来模拟网页上键盘事件的Google Chrome扩展。
由于而无法正常运作我还发现了一些解决方法,例如
然而,定义事件对象的属性不起作用,因为扩展的内容脚本有它自己的并行世界,因此内容脚本中定义的属性对网页脚本不可见。
我唯一的,也是最后一次希望DOM 4 Event Constructors在Google Chrome中工作,并且可以通过构造函数正确初始化键盘事件
var event = new KeyboardEvent(keypress,{key:'U + 0041',char:'a',...})
不幸的是,它失败了:
TypeError:非法构造函数
我无法在Chrome中找到支持的事件构造函数的任何文档。任何人都可以指向我的一些文档/源代码?
用谷歌浏览器扩展模拟键盘事件的其他方式?
(注意,TextEvent不会帮助,因为许多真实世界的控件都会监听 keydown
/ keyup
特别是)
我发现chrome调试器协议v1.1是明确的答案模拟谷歌浏览器扩展程序中的键盘和鼠标事件。部分协议可通过访问。
I'm developing a Google Chrome extension which simulates keyboard events on a web-page.
I found that event.initKeyboardEvent()
does not work properly because of this webkit bug and I also found some workarounds, e.g. SO Question
However, defining properties on event object is not working because extension's content script has its own "parallel world" so properties defined in content script are not visible to web-page script.
My only and last hope that DOM 4 Event Constructors work in Google Chrome and it would be possible to properly initialize keyboard event through constructor
var event = new KeyboardEvent("keypress", {key: 'U+0041', char: 'a', ... })
Unfortunately, it fails with:
TypeError: illegal constructor
I was not able to find any documentation on supported event constructors in Chrome. Could anyone point me to some docs/source code?
Any other way to simulate keyboard events in a Google Chrome extension?
(note, TextEvent won't help because many real-world controls listen to keydown
/keyup
specifically)
I found that chrome debugger protocol v1.1 is the definite answer to simulating key and mouse events from a Google Chrome extension. Part of the protocol is accessible through chrome.debugger API.
这篇关于如何在Chrome扩展中使用给定的char / keycode初始化键盘事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!