document.cookie无法在chrome扩展沙箱中被引用

问题描述 投票:0回答:0

chrome扩展的沙盒中引用document.cookie时出现如下错误

未捕获的 DOMException:无法从“文档”中读取“cookie”属性:该文档是沙盒并且缺少“允许同源”标志。 在 chrome-extension://dmjmafjcmjmkimijfodamlckfkikakjk/sandbox.html:4:26

请告诉我如何解决它。

在 manifest.json 中定义 allow-same-origin 加载 manifest.json 失败。

在iframe标签中设置sandbox="allow-same-origin"会出现如下错误

在“chrome-extension://dmjmafjcmjmkimijfodamlckfkikakjk/sandbox.html”中阻止脚本执行,因为文档的框架是沙箱并且未设置“允许脚本”权限。


在 iframe 标签中设置 sandbox="allow-scripts allow-same-origin" 会导致如下错误。

未捕获的 DOMException:无法从“文档”中读取“cookie”属性:该文档是沙盒并且缺少“允许同源”标志。 在 chrome-extension://dmjmafjcmjmkimijfodamlckfkikakjk/sandbox.html:4:26

清单.json

{
  "manifest_version": 3,
  "name": "foo",
  "version": "1.0",
  "action": {
    "default_popup": "popup.html"
  },
  "sandbox": {
    "pages": [
      "sandbox.html"
    ]
  },
  "content_security_policy": {
    "sandbox": "sandbox allow-scripts"
  }
}

popup.html

<html>
<body>
  <iframe src="sandbox.html"></iframe>
</body>
</html>

sandbox.html

<html>
<body>
  <script>
    console.log(document.cookie);
  </script>
</body>
</html>
google-chrome-extension sandbox chrome-extension-manifest-v3
© www.soinside.com 2019 - 2024. All rights reserved.