问题描述
我正在编写一个Chrome扩展程序,需要在加载时更改流行的Web应用程序。不幸的是,该Web应用程序的大多数用户界面都在iframe中呈现,虽然该iframe的地址与我的 content_scripts
匹配声明相匹配,但只会为用户脚本顶部框架。
I'm writing a Chrome extension that needs to alter a popular web app when loaded. Unfortunately, most of the UI of that web app is rendered inside an iframe, and although the address of that iframe matches my content_scripts
match declaration, the user script only gets invoked for the top frame.
问:是否有方法从Chrome内容脚本扩展中访问iframe中呈现的HTML?如果是,我应该指定什么权限和其他清单选项?谢谢。
Q: Is there a method of accessing HTML rendered inside an iframe from a Chrome content script extension? If yes, what permissions and other manifest options should I specify? Thanks.
推荐答案
我解决了这个问题。必须在manifest.json的content_scripts部分中指定以下选项:all_frames:true
。没有它,该脚本只适用于顶部框架。
I've resolved the problem. The following option has to be specified in the content_scripts section of the manifest.json: "all_frames": true
. Without it, the script is only applied to the top frame.
//有时只需要仔细阅读RTFM。
// Sometimes one just has to RTFM carefully.
这篇关于从Chrome内容脚本扩展程序访问iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!