在我的Chrome扩展中,使用Fetch功能会出错,它不会发送cookie

发布于 2025-02-06 17:19:47 字数 837 浏览 2 评论 0原文

我想调用提取函数以在我的背景中从服务器获取一些数据。 像这样:

    fetch("https://api.bilibili.com/x/space/acc/info?mid=402655790&jsonp=jsonp")
    .then(response=>{
        console.log(response)
    })

但是控制台打印 错误描述照片

我找到了一些解决此问题的方法。 使用模式:“ no-cors”

最后,我成功发送了一个请求,但是没有响应。

请求成功,状态代码== 200 photo

没有数据响应照片

此外,我发现我的请求标题中没有cookie

请求标题照片中没有cookie

我如何成功发送请求,并从服务器中获取正确的数据?

I want to call fetch function to get some data from the server in my background.js。
like this:

    fetch("https://api.bilibili.com/x/space/acc/info?mid=402655790&jsonp=jsonp")
    .then(response=>{
        console.log(response)
    })

but the console print
error description photo

I found some method to solve this problem。
use mode:"no-cors"

Finally, I successfully sent a request,but there was no response.

request success,status code ==200 photo

no data response photo

Besides, I found there is no cookie’s in my request header

no cookies in request header photo

How can I send a request successfully,and get the correct data from the server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执着的年纪 2025-02-13 17:19:47

我发现有一个与我的问题类似的答案,
CORS Chrome Extension带有明显版本2
这个问题是由CORS引起的。
可以通过在清单中添加权限来解决。
像这样:

    "permissions": [
      "https://*/"
    ],

I found that there was an answer similar to my question,
CORS Chrome Extension with manifest version 2
this problem is caused by CORS。
it can be solved by adding permissions to the manifest.json
like this:

    "permissions": [
      "https://*/"
    ],
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文