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

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

问题描述

我正在研究跟踪时间的Chrome扩展程序,并将Google App Engine用于后端。



测试时,我试图连接本地版本扩展到本地版本的App Engine应用程序。当我尝试发送POST请求时,出现:

XMLHttpRequest无法加载 HTTP://本地主机:8080 /报告。 Origin chrome-extension:// mbndmimplohfkkcincjodnfpaapbbmei不被Access-Control-Allow-Origin允许。



但是,当我更改URL时以便它发布到appspot.com网址。



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

解决方案

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

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

请注意,我没有测试过这个,但这听起来就像是您的问题来自哪里。


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?

解决方案

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天全站免登陆