Facebook JavaScript API for google chrome extension

I am making the chrome extension so that it automatically links to specific page posts. Using a simple popup controller and background thread to handle fb api interactive

I can not upload facebook js api to the extension page using an official example.

The jssdk script was downloaded and executed using the developer chrome tools.

But window.FB is not determined by the script loaded !!!

  • I also add the script tag manually.
  • Both a background stream and a pop-up window appeared.
  • If you use an iframe to load the page, it will successfully load window.FB and the login / authentication window pops up. But he had a problem with cross domains.
  • There is a div file # fb-root.
  • menifest.json has content_security_policy
+4
source share
1 answer

I have no solution, but it may lead you in the right direction.

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

From looking at the next line in the jssdk file, it seems that FB also makes this assumption:

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

Try debugging these cases by replacing the line above:

var k = 'http';

Hope this helps.

0
source

Source: https://habr.com/ru/post/1492627/


All Articles