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

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

问题描述

我正在开发一个跟踪时间的 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 不允许 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 扩展程序连接到本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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