Jos*_*Lin 5 javascript google-chrome google-chrome-extension
目前,我们有一个内容脚本,它在manifest.json文件中初始化,如下所示:
"content_scripts": [
{
"matches": [
"https://docs.google.com/*"
],
"js ["content.js"],
"run_at": "document_start",
"all_frames": true,
"match_about_blank": true
}
],
Run Code Online (Sandbox Code Playgroud)
设置为每次用户加载Google文档文档时运行.但是,通过查看控制台日志,似乎内容脚本被多次加载到新选项卡中(是正确的单词注入?),因为我们获得了多个控制台日志.
我已经读过其他一些答案,这可能与内容脚本在加载谷歌文档选项卡时加载一次,以及加载完毕后加载一次这样的事实有关,因此它会运行多次; 虽然如何防止这种情况发生?
问题是"all_frames": true.Google文档嵌入了iframe来自同一域的许多内容:
<iframe src="https://docs.google.com/document/u/0/preload" style="display:none;" tabindex="-1"></iframe>
<iframe src="https://docs.google.com/offline/iframeapi?ouid=REDACTED#cd=1" style="display: none;"></iframe>
Run Code Online (Sandbox Code Playgroud)
您的内容脚本将被注入所有这些帧中.
如果您设置"all_frames": false:您的内容只会被注入到顶部框架中,并且只会在浏览到Google文档文档时记录一次.
| 归档时间: |
|
| 查看次数: |
1250 次 |
| 最近记录: |