How to port a Chrome extension to another Web Browsers [closed]

有些话、适合烂在心里 提交于 2019-12-06 06:47:53

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.

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:

  1. 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.
  2. 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;
  3. Separate HTML from CSS and Javascript, don't make your code dirty and complicated.

Hope this helps :)

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!