如何修复“拒绝加载脚本‘https://connect.facebook.net/en_US/sdk.js’,因为它违反了以下内容安全策略”?

问题描述 投票:0回答:1

我尝试在 chrome 扩展中添加 Facebook 登录 SDK,但出现以下错误:

“拒绝加载脚本‘https://connect.facebook.net/en_US/sdk.js’,因为它违反了以下内容安全策略指令:“script-src 'self' 'unsafe-eval' https ://www.google-analytics.com”。请注意,未明确设置“script-src-elem”,因此“script-src”用作后备”。

我在清单中添加了权限和内容安全策略,但错误未解决。 这是我的家.js

$(".account-with-facebook").click(function(){
alert("fb login btn clicked");
window.fbAsyncInit = function() {
    // FB JavaScript SDK configuration and setup
    FB.init({
      appId      : '2314780002148700', // FB App ID
      cookie     : true,  // enable cookies to allow the server to access the session
      xfbml      : true,  // parse social plugins on this page
      version    : 'v3.2' 
    });

    // Check whether the user already logged in
    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            //display user data
            getFbUserData();
        }
    });
};

// Load the JavaScript SDK asynchronously
(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "https://connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

// Facebook login with JavaScript SDK
function fbLogin() {
    FB.login(function (response) {
        if (response.authResponse) {
            // Get and display the user profile data
            getFbUserData();
        } else {
            console.log('User cancelled login or did not fully authorize.');
        }
    }, {scope: 'email'});
}

// Fetch the user profile data from facebook
function getFbUserData(){
    FB.api('/me', {locale: 'en_US', fields: 
 'id,first_name,last_name,email,link,gender,locale,picture'},
    function (response) {
        console.log(response);
    });
 }

   // Logout from facebook
   function fbLogout() {
      FB.logout(function() {
    });
  }
});      

清单.json

{
"background": {
    "scripts": [
        "js/lib/ga.js",
        "js/lib/jquery.min.js",
        "js/lib/md5.min.js",
        "js/lib/redirect-path.js",
        "js/lib/js.local-session.js",
        "js/lib/js.cookie.js",
        "js/lib/js.storage.js",
        "js/lib/moment.js",
        "js/lib/parser.js",
        "js/ext/background.js"
    ]
},
"browser_action": {
    "default_icon": {
        "38": "icon/default-38.png"
    },
    "default_title": " Cupon Up - Automatic Coupon Finder"
    //"default_popup": "page/store-popup.html"
},
"content_scripts": [
    {
        "all_frames": false,
        "css": ["css/inject-cb-button.css"],
        "js": [
            "js/lib/jquery.min.js",
            "js/lib/md5.min.js",
            "js/lib/jquery.sendkeys.js",
            "js/lib/promise.js",
            "js/lib/js.local-session.js",
            "js/lib/js.cookie.js",
            "js/lib/js.storage.js",
            "js/lib/lang.js",
            "js/lib/i18n.translator.js",
            "js/ext/content.js"
        ],
        "matches": ["http://*/*", "https://*/*"],
        "run_at": "document_end"
    }
],
"content_security_policy": "script-src 'self' https://connect.facebook.net/en_US/sdk.js; object-src 'self'",
"content_security_policy": "script-src 'self' 'unsafe-eval' https://www.google-analytics.com; object-src 'self'",
"description": "Find and Test coupon  on Affiliated sites",
"icons": {
    "128": "icon/logo-128.png",
    "16": "icon/logo-16.png",
    "48": "icon/logo-48.png"
},
//"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgSZyTE0bgqvNL0gZgT0s+DsSDrGO0iskmQR7A/Ayn00oal8Frp6g9kVnh4P+7ZlYqNpF/ggXpprBMLQQAlVo57XRB4rJbHEJOSr5z1qf90NT3zdiNNQdJC6tOTLZMZnR13LA2677Kl7K/u2vR/3r1FcvkeuHC42u2I89h5Vz1s80e9Hc98fsXM0gtiCz1QKW/mf0d4YcFgyLTdvm5106WXEH/maqRKlFuo+w0P33qnRflzX7y2ca4lMYUr5uc2/M9FE1EnhoKfu4c37u/h4773welAafdMWQaI7u/lx+reaQCSPxX6mYIhx4pc7u7RS7hVAQMAWJlRHiRtFxMfSb7QIDAQAB",
"manifest_version": 2,
"name": "Cupon Up",
"permissions": [
    "cookies",
    "tabs",
    "storage",
    "unlimitedStorage",
    "webRequest",
    "webRequestBlocking",
    "http://*/*",
    "https://*/*",
    "https://connect.facebook.net/en_US/sdk.js"
],
//"update_url": "https://clients2.google.com/service/update2/crx",
"version": "1.0",
"default_locale": "en_US",
"web_accessible_resources": ["img/*", "css/*", "page/*"]

}

javascript google-chrome-extension
1个回答
0
投票

这个错误你解决了吗?

现在我在 chrome 扩展中登录 facebook 时遇到同样的错误

© www.soinside.com 2019 - 2024. All rights reserved.