将脚本标签从内容脚本注入脚本标签到使用数据uri src的iframe抛出a' web_accessible_resources'错误甚至正确设置了

发布于 2025-02-13 16:24:56 字数 1892 浏览 1 评论 0原文

我正在研究将一件代码注入iFrame的扩展程序。

我正在使用清单v3,并且有一个内容脚本,该脚本将脚本标签注入了我的代码。

当我们将SRC设置为Data URI之类的iframe时,问题就到了:

< iframe src =“ data:text/html; base64,phnjcmlwd ... 3njcmlwdd4 =”代码>

当内容脚本注入自定义脚本标签时,与创建iframe元素的所有其他可能的方法不同,此一个错误,说脚本标签也不包含在“ web_accessible_resources”中。 (否则,所有其他iframe也将失败)

错误: chrome-extension的负载:// src/dest/paryload-min.js。资源必须在web_accessible_resources中列出,以表明密钥才能由扩展程序之外的页面加载。

我相信这是一个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)

Error: Denying load of chrome-extension://obfggkijinagdggiiigfpppiaoielnjo/src/dest/payload-min.js. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文