最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to port a chrome extension to other browsers? - Stack Overflow

programmeradmin0浏览0评论

Is there a way to port a chrome extension to other browsers, without having to entirely re-write the code? My chrome extension uses the browser_action command to open "popup.html" in the extension window...

Update: I found adblockforchrome port.js and found it only somewhat helpful for porting to Safari...

Is there a way to port a chrome extension to other browsers, without having to entirely re-write the code? My chrome extension uses the browser_action command to open "popup.html" in the extension window...

Update: I found adblockforchrome port.js and found it only somewhat helpful for porting to Safari...

Share Improve this question edited Sep 12, 2014 at 11:50 icc97 12.8k9 gold badges83 silver badges96 bronze badges asked Aug 11, 2010 at 14:17 DavidDavid 14k16 gold badges46 silver badges51 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 5

Apple provides some guidance on how to port convert a Chrome extension to Safari, but the problem you're going to run into is that each browser has a different set of allowed functionality for extensions. Even with Chrome to Safari, there are things you could do in Chrome you can't do in Safari, and visa versa.

It depends on the type of the extension, but not really. To answer your question more clearly, you need to specify what your extension is about: modify some pages (like userscripts/userstyles), extend browsers' features, or something else.

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.

Jumping in a bit late.

Our company - Slice Factory (full disclosure here!) does provide a browser extension conversion service: http://gallery.extensionfactory.com/labs/conversion/ In most cases your chrome extension will work seamlessly in FF and Safari.

The service is still in beta trial, and Firefox conversion is working better than Safari one. I can't fully disclose what's our technical solution, but this being an SO answer, I can add a few details: we have re-developed a full javascript api stack that mimics most of chrome extension APIs for Safari and Firefox; in Firefox we base our work on JetChrome. Plus we have wrappers that re-package the chrome extension adding our library and rewriting manifests and so on.

Beyond that, it's mostly a few good ideas, trial and error, and a LOT of development time.

As an example: Safari 5.1 just introduced a popup corresponding to Chrome's browser_action, but we have already an alternative solution that works for previous versions. Firefox does not support HTML5 WebSQL, but we have an API for it. We also provide a way to bring webapps to FF, and soon to Safari. The objective is to have Chrome API as a reference, and mimic it on all the other browsers.

Without pushing you towards our solution, I might add that the time to fully cover the Chrome API on both Safari and Firefox is probably not worth it - unless you plan to convert several extensions. So for just one or two extensions I would advise making your code as modular as possible, and just creating three extensions - or trying our service!

Yes, it's possible with Webextension API using webextension-polyfill.

I made use of it to build this where I only had to change the callback methods to Promises and using browser.something instead of chrome.something to call the browser APIs.

发布评论

评论列表(0)

  1. 暂无评论