无法从Chrome扩展程序加载facebook js sdk [英] Can't load facebook js sdk from Chrome extension

查看:291
本文介绍了无法从Chrome扩展程序加载facebook js sdk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Chrome浏览器扩展程序中使用facebook sj sdk。
我的扩展名为init:

I'm trying to use facebook sj sdk in a Chrome extension. Im doing this on my extension 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));

我收到此错误:

拒绝加载脚本http://connect.facebook.net/en_US/all.js,因为它违反了以下Content Security Policy指令:script-srcself'chrome-extension-resource:

我将manifest中的permissiosn设置为 http:// * / 。如何从扩展名加载sdk?

I have the permissiosn in manifest set to http://*/. How can I load the sdk from an extension?

推荐答案

这是因为您正在尝试从Chrome扩展程序加载外部脚本。为了安全起见,为了防止跨站点脚本,您需要在 manifest.json 文件中获得特殊许可。

This is because you are trying to load an external script from your Chrome extension. For security reasons to prevent cross-site-scripting you need a special permission in your manifest.json file.

"content_security_policy": "script-src 'self' https://connect.facebook.net; object-src 'self'"

确保使用https://而不是http://。

Make sure you use https:// instead of http://.

这篇关于无法从Chrome扩展程序加载facebook js sdk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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