gpt4 book ai didi

javascript - 是否可以从 Chrome 中的内容脚本执行跨源 XMLHttpRequest?

转载 作者:行者123 更新时间:2023-12-03 05:29:02 28 4
gpt4 key购买 nike

Cross-Origin XMLHttpRequest 的文档看起来只要我使用正确的权限,我就应该能够从通过 https 加载的页面访问 http 资源。然而,在尝试此操作时,我收到以下错误消息。

content.js:1 Mixed Content: The page at 'https://www.example.com/' was loaded over HTTPS, but requested an insecure resource 'http://www.example.com/'. This request has been blocked; the content must be served over HTTPS.

list :

{
"name": "Test Extension",
"version": "0.1",
"permissions": [
"http://www.example.com/*",
"https://www.example.com/*",
],
"content_scripts": [
{
"matches": [
"http://www.example.com/*",
"https://www.example.com/*"
],
"js": ["content.js"],
"run_at": "document_start"
}
],
"manifest_version": 2
}

内容.js:

fetch('http://www.example.com/').then(response => {
console.log('Done!')
});

最佳答案

您的问题不是 CORS。它是混合内容,即使在扩展中也无法解决。

您可以将请求移至后台页面(通过消息传递)。

关于javascript - 是否可以从 Chrome 中的内容脚本执行跨源 XMLHttpRequest?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41028827/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com