2013-04-09 56 views
1

由於這個問題Can't load facebook js sdk from Chrome extension 我基本上是試圖同樣的事情Facebook的JS SDK在我的瀏覽器擴展程序不執行

background.js

(function(d, s, id, debug){ 
var js, fjs = d.getElementsByTagName(s)[0]; 
if (d.getElementById(id)) {return;} 
js = d.createElement(s); js.id = id; 
js.src = "facebook-all.js"; 
fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk', /*debug*/false)); 

window.fbAsyncInit = function() { 
// init the FB JS SDK 
alert('INIT SDK'); 
FB.init({ 
    appId  : 'xxxxxxxxxxx', // App ID from the App Dashboard 
    //channelUrl : '', // 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? 
}); 
FB.login(function(response) { 
    if (response.authResponse) { 
    alert('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     alert('connected ' + JSON.stringify(response, null, 4)); 
    }); 
    } else { 
    alert('User cancelled login or did not fully authorize.'); 
    } 
}); 
}; 

的manifest.json

{ 
"name": "A browser action with no icon", 
"version": "1.0", 
"background": { "scripts":["background.js"]}, 
"permissions": [ 
"tabs", 
"https://*/*", 
], 
"content_security_policy": "default-src https://connect.facebook.net/ https://s-static.ak.facebook.com/connect/ chrome-extension-resource: 'self' 'unsafe-eval' ", 
"manifest_version": 2 
} 

,但即時通訊的在控制檯上獲得以下錯誤:

The "fb-root" div has not been created, auto-creating all.js:52 

Refused to apply inline style because it violates the following Content Security Policy directive: "default-src https://connect.facebook.net/ https://s-static.ak.facebook.com/connect/ 'self' 'unsafe-eval'". Note that 'style-src' was not explicitly set, so 'default-src' is used as a fallback. 

Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "default-src https://connect.facebook.net/ https://s-static.ak.facebook.com/connect/ 'self' 'unsafe-eval'". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback. 

Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "default-src https://connect.facebook.net/ https://s-static.ak.facebook.com/connect/ 'self' 'unsafe-eval'". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback. 

Refused to load the frame 'http://static.ak.facebook.com/connect/xd_arbiter.php?version=21#channel=f30…F_generated_background_page.html%3Ffb_xd_fragment%23xd_sig%3Df2c0b5eef8%26' because it violates the following Content Security Policy directive: "default-src https://connect.facebook.net/ https://s-static.ak.facebook.com/connect/ 'self' 'unsafe-eval'". Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback. 

Refused to load the frame 'https://www.facebook.com/dialog/oauth?client_id=xxxxxxxxxxx&response_type=…4%26domain%3D<extension-id>%26relation%3Dparent&sdk=joey' because it violates the following Content Security Policy directive: "default-src https://connect.facebook.net/ https://s-static.ak.facebook.com/connect/ 'self' 'unsafe-eval'". Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback. 

我知道'不安全的內聯'不再被允許了,那麼有沒有辦法讓chrome擴展中的fs-jssdk正常工作?

任何幫助將不勝感激!

obs:我能夠直接在瀏覽器中從FB中獲取結果,但不能在擴展中獲取。

回答

0

可以使樣式和框架具有以下內容:

"content_security_policy": "default-src 'self' 'unsafe-eval' chrome-extension-resource: https://*.facebook.net https://*.facebook.com; style-src 'self' 'unsafe-inline' chrome-extension-resource: https://*.facebook.net https://*.facebook.com; frame-src 'self' 'unsafe-inline' chrome-extension-resource: https://*.facebook.net https://*.facebook.com", 

,但我不知道如何擺脫Refused to load the frame 'http://static.ak.facebook.com(...)錯誤的。谷歌瀏覽器的CSP不允許允許http://域,如果沒有它,則不存在內部通信,因此例如自動調整大小將不起作用。

相關問題