无法从 Chrome 扩展程序连接到 localhost [英] Can't connect to localhost from Chrome extension

查看:70
本文介绍了无法从 Chrome 扩展程序连接到 localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个跟踪时间的 Chrome 扩展程序,并使用 Google App Engine 作为后端.

I am working on a Chrome extension that tracks time, and uses Google App Engine for the backend.

为了进行测试,我正在尝试将本地版本的扩展程序连接到本地版本的 App Engine 应用.当我尝试发送 POST 请求时,我得到:

For testing, I'm trying to connect a local version of the extension to a local version of the App Engine app. When I try to send a POST request, I'm getting:

XMLHttpRequest 无法加载 http://localhost:8080/report.Access-Control-Allow-Origin 不允许来源 chrome-extension://mbndmimplohfkkcincjodnfpaapbbmei.

XMLHttpRequest cannot load http://localhost:8080/report. Origin chrome-extension://mbndmimplohfkkcincjodnfpaapbbmei is not allowed by Access-Control-Allow-Origin.

但是当我更改 URL 以便它发布到 appspot.com URL 时它可以工作.

But it works when I change the URL so that it posts to the appspot.com URL.

什么是 Access-Control-Allow-Origin,为什么它阻止我从 localhost 获取结果?

What is the Access-Control-Allow-Origin, and why is it stopping me from getting results from localhost?

推荐答案

我相信这是因为您无法调用未包含在清单的权限部分中的服务器.manifest.json 的权限部分应如下所示:

I believe this is because you cannot make calls to a server that is not included in the permissions section of your manifest. The permissions section of manifest.json should look something like this:

"permissions": [
    "http://myapp.appspot.com/*",
    "http://localhost/*"
]

注意,我没有对此进行测试,但听起来这就是您的问题所在.

Note, I haven't tested this, but it sounds like that is where your problem is coming from.

这篇关于无法从 Chrome 扩展程序连接到 localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆