igorpavlov
igorpavlov

Reputation: 3626

Port Chrome Extension to Firefox, Safari, IE

I would like to start making a cross-browser extension. I understand that all APIs and structures are different per browser, but is there any universal practice to follow?

I have searched over Stackoverflow and none of questions provide a universal solution to produce cross-browser extensions.

Upvotes: 1

Views: 1245

Answers (1)

Mathieu Bertin
Mathieu Bertin

Reputation: 1624

From my experience, The best solution is to use adapters class that will call browser api. After you can have a code that will work on every browser by using the right adapter.

For example in the background script you don't have setTimeout/setInterval for firefox but you have it for chrome. You can have a code like this

Core.js

this._browserAdapter.setTimeout(function(){...}, 1000);

ChromeAdapter.js

setTimeout: function (callback, time) {
        return setTimeout(callback, time);
}

FirefoxAdapter.js

setTimeout: function(callback, time) {

        var {setTimeout} = require("sdk/timers");
        return setTimeout(callback, time);
},

You can do everything using this way, so you will be able to have more than 90% of your code in common.


Edit

It will work for firefox and safari. For IE it's completely different, but with the new microsoft EDGE I think it will be possible to have something like this. Wait and see !

Upvotes: 3

Related Questions