清单版本2的CORS Chrome扩展 [英] CORS Chrome Extension with manifest version 2

查看:104
本文介绍了清单版本2的CORS Chrome扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写Google Chrome扩展程序时可以使用CORS吗?

Is it possible to use CORS when writing a google chrome extension?

我看到了这个,
http://developer.chrome.com/extensions/contentSecurityPolicy.html

我尝试将它插入清单中,
content_security_policy:script-src'self' https:// twitter。 com / ; 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无法加载 https://twitter.com/ 。 Origin chrome-extension:// olimhkjfpndfhdopbneamnekfalckinc不被Access-Control-Allow-Origin允许。

but an ajax requestion fails with XMLHttpRequest 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扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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