0

I currently have a Chrome extension that uses Chrome's APIs and plan on making a Microsoft Edge version once it opens up as well. My question is how do you work with the multiple API's?

For example, I use the following to check if the extension has just been installed or not:

chrome.runtime.onInstalled

I'm assuming for Edge it would be something like:

edge.runtime.onInstalled

What's the best way to work with both of these? Do I just duplicate the code within the file where there is a copy of the code for one and the other and presumably the browser will ignore the other browser's code? (doesn't sound like the good option)

Or is there some cross-browser framework that I should use instead?

Or is there some other solution?

And please forgive me, this is my first entry into building extensions/apps, I'm generally just a Web Designer.

Thank you!

BlueCaret
  • 4,719
  • 7
  • 30
  • 48

1 Answers1

1

All browsers support or

chrome.runtime.onInstalled

or

browser.runtime.onInstalled

So, the right way is to start scripts in your extension with this code:

var browser = browser || chrome

And then use browser, for example:

browser.runtime.onInstalled

(I'm sorry about my english)

Edit:

Chrome and Opera support chrome and not browser.

Firefox support chrome and browser.

Edge support browser and I don't know if it support chrome.

Anyway, my solution work in all browsers.

Update (5.8.16):

Edge support browser and not chrome.

Elad
  • 1,114
  • 8
  • 15