20

有没有办法将 chrome 扩展移植到其他浏览器,而无需完全重新编写代码?我的 chrome 扩展使用browser_action命令在扩展窗口中打开“popup.html”...

更新:我发现adblockforchrome port.js并发现它对移植到 Safari 有点帮助......

4

4 回答 4

5

Apple提供了一些关于如何将 Chrome 扩展程序移植到 Safari 的指导,但您将遇到的问题是每个浏览器都有一组不同的允许的扩展功能。即使使用 Chrome 到 Safari,也有一些您可以在 Chrome 中执行但在 Safari 中无法执行的操作,反之亦然。

于 2010-08-14T08:58:47.607 回答
4

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!

于 2011-09-15T14:18:20.457 回答
4

这取决于扩展的类型,但不是真的。为了更清楚地回答您的问题,您需要指定扩展的内容:修改某些页面(如用户脚本/用户样式)、扩展浏览器的功能或其他内容。

但是,有一些可移植性说明可以帮助您简化此过程:

  1. 不要编写特定于浏览器的代码。在某些现代浏览器中,您可以使用 HTML5 功能,例如 Web SQL 数据库 API。例如,很难在 IE 上模拟这种行为。
  2. 保持 JavaScript 模块化;不要使用供应商特定的 JavaScript 方法,您的代码将是可移植的,并且不会依赖于 TraceMonkey 或 V8;
  3. 将 HTML 从 CSS 和 Javascript 中分离出来,不要让你的代码变得肮脏和复杂。
于 2010-08-11T17:07:42.743 回答
0

是的,使用webextension- polyfill 的 Webextension API 是可能的。

我利用它来构建,我只需将回调方法更改为 Promises 并使用browser.something而不是chrome.something调用浏览器 API。

于 2019-01-13T13:56:36.073 回答