问题描述
在编写Google Chrome扩展程序时可以使用CORS吗?
Is it possible to use CORS when writing a google chrome extension?
我看到了这个,
我尝试将它插入清单中,
content_security_policy:script-src'self'; object-src'self',
And I tried inserting this into the manifest,"content_security_policy": "script-src 'self' https://twitter.com/; object-src 'self'",
但ajax请求失败,返回
XMLHttpRequest无法加载。 Origin chrome-extension:// olimhkjfpndfhdopbneamnekfalckinc不被Access-Control-Allow-Origin允许。
but an ajax requestion fails withXMLHttpRequest cannot load https://twitter.com/. Origin chrome-extension://olimhkjfpndfhdopbneamnekfalckinc is not allowed by Access-Control-Allow-Origin.
推荐答案
=http://developer.chrome.com/extensions/xhr.html =noreferrer>交叉来源Ajax 从您的扩展到Twitter,您只需将Twitter列为主机权限清单:
To enable cross-origin Ajax from your extension to Twitter, you simply need to list Twitter as a host permission in your manifest:
...
"permissions": [
"*://*.twitter.com/*"
],
...
这篇关于清单版本2的CORS Chrome扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!