2

I am trying to use my Chrome extension on Microsoft Edge to adapt it, but I can't build the popup because in the script of my popup, some variables seem to not exist:

var bg = chrome.extension.getBackgroundPage();

This line isn't working, it supposed to access data of content scripts. I've found some guys saying browser.extension.getBackgroundPage() must be used to replace it, but it doesn't work to.

By what should I replace this line?

Nucktrooper
  • 245
  • 1
  • 15
  • Did you assign `chrome = browser` already? This API is [currently documented](https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/extensions/api-support/supported-APIs/#extension) as being *supported* in Microsoft Edge. – Sampson Jul 20 '16 at 23:31
  • No, but I've remplaced it by browser.extension.getBackgroundPage() as shown in the documentation and It doesn't work. How can I display my variables? It would help me to debug, and console.log doesn't work in background and content scripts. – Nucktrooper Jul 20 '16 at 23:52
  • Note to others **this question and the answers are regarding the legacy Microsoft Edge**. Not the current Chromium based Edge. – mikemaccana Oct 27 '22 at 14:32

2 Answers2

4
  1. Since Microsoft Edge uses browser.* namespace, you should use browser.extension.getBackgroundPage() instead.

  2. For debugging background script and content script, see Debugging extensions for more details

  3. For debugging popup scripts, it seems there is no visible entry. One workaround would be manually opening that page in Microsoft Edge via typing the popup url, something like ms-browser-extension://[Extension_Id]/html/popup.html

Haibara Ai
  • 10,703
  • 2
  • 31
  • 47
  • Spent lot of time trying to see content script output with debugging tools. Seems it is also bugged, only way to see it is to look at page : ms-browser-extension://[Extension_Id]/_generated_background_page.html – Nucktrooper Jul 21 '16 at 02:30
  • @Nucktrooper, content script are injected into web page, it's in the page's f12 tool; background page lives in the extension context, you would need to view it through "Inspect Background page". What do you mean "generated_background_page" ? – Haibara Ai Jul 21 '16 at 02:32
  • In "Inspect Background page" there is nothing in console, but when I open ms-browser-extension://[Extension_Id]/_generated_background_page.html logs from of background scripts are displayed, as ms-browser-extension://[Extension_Id]/html/popup.html able me to see logs from content script. – Nucktrooper Jul 21 '16 at 02:55
2

There is a software named "Tool kit" provided by Microsoft to convert your existing chrome extension to Microsoft extension by bridging the Chrome APIs. This tool help to remove errors from the convertible version and also highlights the syntax error which not allowed in edge extension.

Atif Hussain
  • 880
  • 12
  • 19