简体   繁体   English

Chrome扩展许可权XMLHttpRequest

[英]Chrome extension permission XMLHttpRequest

I am coding a chrome extension for first time. 我是第一次编写Chrome扩展程序。 Read out their documentation well, specially permission section. 仔细阅读他们的文档,特别是权限部分。

I want to load a JSON response from my localhost with a specific port ex. 我想使用特定的端口ex从本地主机加载JSON响应。 3000. 3000。

I updated my mainfest.json and persssion section is like 我更新了mainfest.json和persssion部分就像

  "permissions": [
    "http://localhost:3000/*"
  ],

But getting XMLHttpRequest cannot load http://localhost:3000/project/data.json Origin null is not allowed by Access-Control-Allow-Origin. 但是获取XMLHttpRequest cannot load http://localhost:3000/project/data.json Origin null is not allowed by Access-Control-Allow-Origin.

Seems I am missing something. 似乎我缺少了一些东西。

What am I missing? 我想念什么?

You could try any of the following solutions: 您可以尝试以下任何一种解决方案:

  1. Add the following line to the end of your manifest file: 将以下行添加到清单文件的末尾:

     "content_security_policy": "script-src 'self' http://localhost:3000; object-src 'self'" 
  2. Instead of localhost ,try using the address instead ie 127.0.0.1 代替localhost ,尝试使用地址代替,即127.0.0.1

Hope it helps. 希望能帮助到你。

If your request is sent to the same host with other port then this is already a cross domain request (please see http://en.wikipedia.org/wiki/Same_origin_policy#Origin_determination_rules ). 如果您的请求与其他端口一起发送到同一主机,则该请求已经是跨域请求(请参见http://en.wikipedia.org/wiki/Same_origin_policy#Origin_determination_rules )。 Cross domain ajax requsts are not allowed. 不允许跨域ajax请求。 There are two solutions: 有两种解决方案:

  1. To use JSONP request. 使用JSONP请求。
  2. To add to the response header an option: Access-Control-Allow-Origin: * But not all browsers support this feature. 要在响应头中添加一个选项: Access-Control-Allow-Origin:*但并非所有浏览器都支持此功能。

Please see: 请参见:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM