无法从 Chrome 扩展程序连接到本地主机
我正在开发一个跟踪时间的 Chrome 扩展,并使用 Google App Engine 作为后端。
为了进行测试,我尝试将扩展程序的本地版本连接到 App Engine 应用程序的本地版本。当我尝试发送 POST 请求时,我收到:
XMLHttpRequest 无法加载 http://localhost:8080/report。 Access-Control-Allow-Origin 不允许 Origin chrome-extension://mbndmimplohfkkcincjodnfpaapbbmei。
但当我更改 URL 以便将其发布到 appspot.com URL 时,它会起作用。
什么是 Access-Control-Allow-Origin,为什么它阻止我从本地主机获取结果?
I am working on a Chrome extension that tracks time, and uses Google App Engine for the backend.
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 cannot load http://localhost:8080/report. Origin chrome-extension://mbndmimplohfkkcincjodnfpaapbbmei is not allowed by Access-Control-Allow-Origin.
But it works when I change the URL so that it posts to the appspot.com URL.
What is the Access-Control-Allow-Origin, and why is it stopping me from getting results from localhost?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信这是因为您无法调用未包含在清单的权限部分中的服务器。
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:Note, I haven't tested this, but it sounds like that is where your problem is coming from.
您可以使用自定义端口。
manifest.json
background.js (使用 jQuery)
You can use custom ports.
manifest.json
background.js (using jQuery)
我能够让这段代码工作:
编辑:
显然有人不喜欢这个,所以要记住一些事情:
I was able to get this code to work:
EDIT:
Apparently someone didn't like this, so a few things to keep in mind:
如果您想要通用的本地主机方法
if you want a generic localhost approach