为什么web_accessible_resource能够访问 chrome 扩展程序中的其他非web_accessible_resource?

Why is a web_accessible_resource able to access other non - web_accessible_resource in chrome extension?

提问人:Kritidipto Ghosh 提问时间:7/12/2023 最后编辑:Kritidipto Ghosh 更新时间:7/12/2023 访问量:77

问:

我有一个正在本地开发的 chrome MV3 扩展。 现在,我有一个内容脚本,可以将 iframe 注入用户站点。 iframe 的 html src 是一个文件,我们使用 url 。 现在这个文件也链接了 a & a。sample.htmlchrome.runtime.getURL('/iframeinjector/sample.html'))sample.csssample.js

当我声明iframe时.html web_accessible_resource我也可以导入css和js文件,而无需web_acesssible_resources这些文件。

如果我不web_accessible_resources中声明它.html预计我无法访问 iframe。那么为什么我能够访问 CSS/JS 文件而不将它们声明为 web_accessible_resource .

manifest.json

...
"web_accessible_resources": [
{
    "resources": [
        "/iframeinjector/sample.html",
    ],
    "matches": ["<all_urls>"],
    "extension_ids": ["extension_id1234"]
}]
...

内容脚本.js

$injectedIframe.setAttribute('id', 'extension-iframe');
$injectedIframe.setAttribute('src', chrome.runtime.getURL('/injectediframe/sample.html'));

示例:.html(iframe src)

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="bootstrap/built.min.css"></link>
  </head>
  <body >
    <script type="text/javascript" src="./script.js"></script>
  </body>
</html>

我上传到 chrome 的 dist 包含那些 js 和 css 文件。 鉴于web_accessible_resource的定义,如果资源未列出,我不希望资源可用。

javascript chrome chrome-extension-manifest-v3 chrome-extension-manifest-v2

评论

1赞 wOxxOm 7/13/2023
因为 iframe 是一个带有 URL 的不同文档,所以它可以访问此路径中的所有内容,即扩展的所有资源。chrome-extension://id/

答: 暂无答案