【问题标题】:Chrome Extensions - make a cross domain AJAX requestChrome 扩展 - 发出跨域 AJAX 请求
【发布时间】:2013-06-04 20:13:17
【问题描述】:

我正在从事实验性的边做边学项目。 我的 chrome 扩展(在本地加载解包)有一些 AJAX 调用(跨域,JSONP)

很遗憾,我收到以下错误消息:

Refused to load the script 'http://localhost:3318/servicestack.ashx/api/?callback=cb&ActionName=DoStuff&_=1370346168979' because it violates the following Content Security Policy directive: "script-src 'self' http://localhost".

这是我的清单文件:

{
  "manifest_version": 2,

  "name": "Testing Chrome",
  "description": "Test test test",
  "version": "1.0",
  "permissions" : [  
    "http://localhost/"   
  ],

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "index.html"
    },
    "content_security_policy": "script-src 'self' http://localhost; object-src 'self'"
  }

请问有什么问题的建议吗?

【问题讨论】:

    标签: ajax google-chrome-extension cross-domain jsonp


    【解决方案1】:

    对通过 HTTP 加载的资源的限制仅适用于 那些直接被执行的资源。

    脚本是直接执行还是有JSONP机制?

    【讨论】:

    • 感谢您抽出宝贵时间。不知道你说的直接执行是什么意思,ajax 调用返回 JSON 数据。
    • @User789:您能否提供它返回的示例输出?
    • 问题已解决。我必须添加端口号"content_security_policy": "script-src 'self' http://localhost:3318; object-src 'self'"
    • 返回的 JSON 示例:cb({"0":{"Error":"Wrong Password Or Username!"}})
    猜你喜欢
    • 2012-04-22
    • 1970-01-01
    • 2023-03-20
    • 2018-04-12
    • 2014-03-04
    • 1970-01-01
    • 2012-04-01
    • 2016-08-28
    • 1970-01-01
    相关资源
    最近更新 更多