将脚本标签从内容脚本注入脚本标签到使用数据uri src的iframe抛出a' web_accessible_resources'错误甚至正确设置了
我正在研究将一件代码注入iFrame的扩展程序。
我正在使用清单v3,并且有一个内容脚本,该脚本将脚本标签注入了我的代码。
当我们将SRC设置为Data URI之类的iframe时,问题就到了:
< iframe src =“ data:text/html; base64,phnjcmlwd ... 3njcmlwdd4 =”代码>
当内容脚本注入自定义脚本标签时,与创建iframe元素的所有其他可能的方法不同,此一个错误,说脚本标签也不包含在“ web_accessible_resources”中。 (否则,所有其他iframe也将失败)
我相信这是一个chrome错误,但我要求另一种方法来实现我的目标,然后再联系Chrome Dev Group 。
sustest.json:
{
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"incognito": "spanning",
"background": {
"service_worker": "background.js"
},
"permissions": [
"browsingData",
"windows",
"activeTab",
"tabs",
"webNavigation",
"webRequest",
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess",
"declarativeNetRequestFeedback"
],
"host_permissions": [ "*://*/*" ],
"content_scripts": [
{
"all_frames" : true,
"run_at" : "document_start",
"match_about_blank" : true,
"match_origin_as_fallback": true,
"matches": ["*://*/*"],
"js": ["./content-script.js"]
}
],
"web_accessible_resources": [
{
"resources": [ "/src/dest/payload-min.js" ],
"matches": [ "<all_urls>" ]
}
]
}
content-script.js:
var script = document.createElement('script')
script.setAttribute('class', 'myScriptClass')
script.src = chrome.runtime.getURL('/src/dest/payload-min.js')
;(document.head||document.documentElement).appendChild(script)
I'm working on an extension that injects a piece of code into iframes.
I'm using manifest v3 and I have a content script that injects a script tag with my code into the iframes.
The issue comes when we have an iframe with src set as data URI like so:
<iframe src="data:text/html;base64,PHNjcmlwd...3NjcmlwdD4="></iframe>
When the content script injects the custom script tag, unlike all other possible ways to create an iframe element, this one throws an error saying the script tag is not included in the "web_accessible_resources" even tho it is. (otherwise, all other iframes would fail as well)
I believe this is a chrome bug but I'm asking for an alternative way to achieve my goal before contacting the chrome dev group.
manifest.json:
{
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"incognito": "spanning",
"background": {
"service_worker": "background.js"
},
"permissions": [
"browsingData",
"windows",
"activeTab",
"tabs",
"webNavigation",
"webRequest",
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess",
"declarativeNetRequestFeedback"
],
"host_permissions": [ "*://*/*" ],
"content_scripts": [
{
"all_frames" : true,
"run_at" : "document_start",
"match_about_blank" : true,
"match_origin_as_fallback": true,
"matches": ["*://*/*"],
"js": ["./content-script.js"]
}
],
"web_accessible_resources": [
{
"resources": [ "/src/dest/payload-min.js" ],
"matches": [ "<all_urls>" ]
}
]
}
content-script.js:
var script = document.createElement('script')
script.setAttribute('class', 'myScriptClass')
script.src = chrome.runtime.getURL('/src/dest/payload-min.js')
;(document.head||document.documentElement).appendChild(script)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论