简体   繁体   English

适用于Google Chrome扩展程序的Facebook JavaScript API

[英]Facebook JavaScript API for google chrome extension

I make a chrome extension to like specific page posts automatically. 我自动将Chrome扩展程序设为特定页面帖子。 With a simple popup controller and background thread to handle fb api interactive 用一个简单的弹出控制器和后台线程来处理fb api交互

I cannot load facebook js api into extension page with official example method. 我无法使用官方示例方法将facebook js api加载到扩展页面。

The script jssdk was loaded and executed checked by chrome developer tools. 脚本jssdk由chrome开发人员工具加载并执行检查。

But window.FB is not defined by script loaded!!! 但是window.FB没有被加载的脚本定义!!!

  • 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. 如果使用iframe注入加载页面,它将成功加载window.FB并弹出登录/验证窗口。 But it had a cross domain problem! 但它有一个跨域问题!
  • The div#fb-root is exist. div#fb-root存在。
  • menifest.json has content_security_policy menifest.jsoncontent_security_policy

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. 问题可能在于扩展文档的document.location。 For javascript running in the extension scope, the protocol is "chrome-extension://", while many JS libraries expect either "http" or "https". 对于在扩展范围内运行的javascript,协议是“chrome-extension://”,而许多JS库需要“http”或“https”。

From looking at the following line at the jssdk file, it seems that FB make this assumption as well: 通过查看jssdk文件中的以下行,似乎FB也做出了这样的假设:

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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM