I wanted to know the best way to bring a Chrome extension on another browser, use Crossbrowser , re-coding is not an option as its very large.
问题:
回答1:
the best way to port a chrome extension is to look into WebExtension: https://wiki.mozilla.org/WebExtensions
https://developer.mozilla.org/en-US/Add-ons/WebExtensions
Firefox already is on its way to support it: https://blog.mozilla.org/addons/2015/08/21/the-future-of-developing-firefox-add-ons/
and also Microsoft Edge has promissed to support the chrome APIs and already supports some chrome.* apis ive tried: http://www.winbeta.org/news/new-microsoft-edge-browser-can-use-chrome-and-firefox-extensions
Hopefully in a few months this will all work in production. Of course your code should still be cross-browser (another answer here has some tips) and this answer covers support for special extensions API.
回答2:
The argument here is based on the type of the extension but in most cases it is not the case that one would be able to transfer the extension from one browser to another. To answer the argument here, you need to specify what your extension is about, if it’s only related to modifying some pages (like userscripts/userstyles), extend browsers' features, or something else, as this does play a difference in the subject. There are a few portability notes, however, that could help you to simplify this process:
- Don't write browser specific code. In some modern browsers you're able to use HTML5 features, like Web SQL Database API. It is difficult to emulate such behaviour on IE, for instance.
- Keep your JavaScript modular; don't use vendor specific JavaScript methods, and your code will be portable and will not rely on TraceMonkey or V8;
- Separate HTML from CSS and Javascript, don't make your code dirty and complicated.
Hope this helps :)
回答3:
I created this library to make crossbrowser way to write one code that will work in both FF/Chrome. But it based on promises behaviour (FF way). So it will be helpful for those who starting to write new extension. In your case you'll need to rewrite all callback behaviour to promise behaviour, but after that done, code will be much cleaner.
https://github.com/lawlietmester/webextension
Keep in mind that some APIs has absolutely different realizations in FF and Chrome, like Proxy API (not Proxy object).