MeL*_*ght 4 facebook google-chrome google-chrome-extension facebook-javascript-sdk
我正在尝试在Chrome扩展程序中使用facebook sj sdk.我在我的扩展程序init上执行此操作:
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId: 'APP_ID', // App ID from the App Dashboard
//channelUrl : '//www.example.com/', // Channel File for x-domain communication
status: true, // check the login status upon init?
cookie: true, // set sessions cookies to allow your server to access the session?
xfbml: true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
console.log(FB);
};
// Load the SDK's source Asynchronously
(function(d, debug) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "http://connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/false));
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
拒绝加载脚本'http://connect.facebook.net/en_US/all.js',因为它违反了以下内容安全策略指令:"script-src'self'chrome-extension-resource:".
我有清单中的权限http://*/.如何从扩展程序加载sdk?
这是因为您尝试从Chrome扩展程序加载外部脚本.出于安全原因,要防止跨站点脚本,您需要在manifest.json文件中拥有特殊权限.
"content_security_policy": "script-src 'self' https://connect.facebook.net; object-src 'self'"
Run Code Online (Sandbox Code Playgroud)
确保使用https://而不是http://.
| 归档时间: |
|
| 查看次数: |
3266 次 |
| 最近记录: |