Facebook JavaScript API for google chrome extension

╄→гoц情女王★ 提交于 2019-12-22 08:25:38

问题


I make a chrome extension to like specific page posts automatically. With a simple popup controller and background thread to handle fb api interactive

I cannot load facebook js api into extension page with official example method.

The script jssdk was loaded and executed checked by chrome developer tools.

But window.FB is not defined by script loaded!!!

  • I also add script tag manually.
  • It appeared both background thread and popup window.
  • If inject with iframe to load page, it will success loaded window.FB and popup a login/authenticate window. But it had a cross domain problem!
  • The div#fb-root is exist.
  • menifest.json has content_security_policy
    • script-src 'self' https://connect.facebook.net; object-src 'self'

回答1:


I don't have a solution, but this might lead you in the right direction.

The problem might be with the document.location of the extension document. For javascript running in the extension scope, the protocol is "chrome-extension://", while many JS libraries expect either "http" or "https".

From looking at the following line at the jssdk file, it seems that FB make this assumption as well:

var k = typeof j == 'undefined' ? location.protocol.replace(':', '') : j ? 'https' : 'http';

Try debugging these cases, replacing the line above with something like:

var k = 'http';

Hope this helps.



来源:https://stackoverflow.com/questions/17779239/facebook-javascript-api-for-google-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!