有没有办法将 Chrome 扩展移植到其他浏览器?
有没有办法将 Chrome 扩展移植到其他浏览器,而无需完全重写代码?我的 Chrome 扩展程序使用 browser_action 命令在扩展程序中打开“popup.html”窗口...
更新:我发现 adblockforchrome port.js 并发现它对于移植到 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Apple 提供了一些关于如何操作的指南将 Chrome 扩展程序移植到 Safari,但您将遇到的问题是每个浏览器都有一组不同的允许扩展程序功能。即使从 Chrome 到 Safari,有些事情在 Chrome 中可以做到,而在 Safari 中却无法做到,反之亦然。
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:
跳进去有点晚了。
我们公司 - Slice Factory(在此全面披露!)确实提供浏览器扩展转换服务: http://gallery .extensionfactory.com/labs/conversion/
在大多数情况下,您的 Chrome 扩展程序可以在 FF 和 Safari 中无缝运行。
该服务仍处于测试阶段,Firefox 转换效果比 Safari 更好。
我无法完全透露我们的技术解决方案是什么,但这是一个 SO 答案,我可以添加一些细节:我们重新开发了一个完整的 javascript api 堆栈,它模仿了 Safari 和 Firefox 的大多数 chrome 扩展 API;在 Firefox 中,我们的工作基于 JetChrome。另外,我们还有包装器,可以重新包装 chrome 扩展,添加我们的库并重写清单等。
除此之外,主要是一些好主意、反复试验以及大量的开发时间。
举个例子:
Safari 5.1 刚刚引入了与 Chrome 的 browser_action 相对应的弹出窗口,但我们已经有了适用于以前版本的替代解决方案。 Firefox 不支持 HTML5 WebSQL,但我们有一个 API。我们还提供了一种将网络应用程序引入 FF 并很快引入 Safari 的方法。
目标是以 Chrome API 作为参考,并在所有其他浏览器上模仿它。
在不推动您采用我们的解决方案的情况下,我可能会补充一点,在 Safari 和 Firefox 上完全覆盖 Chrome API 的时间可能不值得 - 除非您计划转换多个扩展。因此,对于一两个扩展,我建议您的代码尽可能模块化,并且只创建三个扩展 - 或者尝试我们的服务!
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!
是的,可以使用 webextension-polyfill 来使用 Webextension API。
我利用它来构建 this 我只需将回调方法更改为 Promises 和使用
browser.something
而不是chrome.something
来调用浏览器 API。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 ofchrome.something
to call the browser APIs.