4

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));

次のエラーが表示されます。

スクリプト「http://connect.facebook.net/en_US/all.js」の読み込みを拒否しました。これは、次のコンテンツ セキュリティ ポリシー ディレクティブ「script-src 'self' chrome-extension-resource:」に違反しているためです。

マニフェストの許可を に設定していhttp://*/ます。拡張機能から sdk をロードするにはどうすればよいですか?

4

1 に答える 1

6

これは、Chrome 拡張機能から外部スクリプトをロードしようとしているためです。クロスサイト スクリプティングを防止するためのセキュリティ上の理由から、manifest.jsonファイルには特別なアクセス許可が必要です。

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

http:// ではなく https:// を使用してください。

于 2012-11-18T19:59:30.327 に答える