更新时间:2021-07-21 09:26:50
我在g-docs或g-sheets上看不到用于主要内容的iframe,但是如果您坚持可以使用和,使其自动在所有iframe中运行.
I don't see iframes used for the main content on g-docs or g-sheets, but if you insist you can use "all_frames": true and "match_about_blank": true in manifest.json content script declaration to make it run in all iframes automatically.
另一个想法是在网站看到事件之前捕获事件:声明"run_at":"document_start "用于manifest.json中的内容脚本,并将true
用于 useCapture 参数:document.addEventListener("keydown", handler, true);
-在构建页面DOM之前,应在内容脚本的主代码中执行此行,以注册侦听器,请勿将其放在某些load
或DOMContentLoaded
回调.
Another idea is to capture events before the site sees them: declare "run_at": "document_start" for your content script in manifest.json and use true
for useCapture parameter of addEventListener: document.addEventListener("keydown", handler, true);
- this line should be executed in the main code of your content script to register the listener before the page DOM is built, don't put it inside some load
or DOMContentLoaded
callback.