>_< 今天无聊的时候,了解了下 Firefox 跟 Chrome 的扩展,然后在 MDN 发现了一些很有意思的东西。
首先是这个 https://developer.mozilla.org/zh-CN/Add-ons
目前有几种工具用于开发的 Firefox 附加组件, 但是 WebExtensions 将会在 2017 年年末后成为事实上的标准。其余的都会在同一时期被弃用。
在这里你会找到一些有用的用于开发附加组件的信息,这样就可以决定是现在和将来的最适合你的根据。
既然这样我就看看这个 WebExtesions 吧,这里中文翻译不是很完善,跟英文资料对照着看
https://developer.mozilla.org/en-US/Add-ons/WebExtensions
然后这边就介绍了一些 JS API:
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API
以及浏览器的支持状况:
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Browser_support_for_JavaScript_APIs
先不管 Firefox Mobile,Chrome 跟 Opera 几乎全绿,Firefox Desktop 从 45+ 开始大多特性都支持,Edge 都支持了一堆特性 … Bookmarks,tabs,history … 看起来好厉害的样子
那这东西怎么写呢,正好 MDN 上 WebExtensions 这页有个示例:
目测需要一个 manifest.json 一个 icon 和 一个 js 文件就行了!?
于是我也跟着写了一个,给 mozilla.org 的页面加个红边框

Firefox 临时加载扩展,选择 manifest.json 就可用了

然后就是红边框:

想想之前看到的介绍,Chrome 能不能用呢? 加载已解压的扩展程序:

也成功了:

那回头看 WebExtensions 到底是什么呢
WebExtensions are a cross-browser system for developing browser add-ons. To a large extent the API is compatible with the extension API supported by Google Chrome and Opera. Extensions written for these browsers will in most cases run in Firefox or Microsoft Edge with just a few changes. The API is also fully compatible with multiprocess Firefox.
WebExtensions(扩展)是跨浏览器的用于开发附加组件的工具。 在很大程度上,与谷歌浏览器 Chrome 和欧朋浏览器 Opera 所支持的扩展API 兼容。 为这些浏览器所写的扩展在大多数情况下只需少量修改的便可在火狐浏览器 FireFox 和 Microsoft Edge 浏览器上运行。 这些API与多线程Firefox完全兼容。
然后下面这段内容来自 Mozilla Add-ons Blog
Firefox and Chrome are different browsers, so some APIs from Chrome do not translate directly. … WebExtensions APIs will never completely mirror Chrome’s extension APIs, for the reasons outlined above. We are, however, already reaching a point where the majority of Chrome extensions work in Firefox.
To make writing extensions for multiple browsers as easy as possible, Mozilla has been participating in a W3C community group for extension compatibility. Also participating in that group are representatives of Opera and Microsoft. We’ll be sending a representative to TPAC this month to take part in discussions about this community group so that we can work towards a common browser standard for browser extensions.
Update: please check the MDN page on incompatibilities . https://blog.mozilla.org/addons/2016/09/13/webextensions-and-parity-with-chrome/
-
- 不知道该怎么总结了,大概是 FF 推出一套一定程度上兼容 Chrome 的扩展机制(Edge也有),并加入一个 W3C 工作组完善这个方案,同时工作组内还有 MS 跟 Opera 的代表,刚看了下好像还有 Google 的人 … 很神奇的事情哇,期待后续