创建跨浏览器Gmail扩展程序的最佳方式是什么? [英] What is the best way to create a cross browser Gmail extension?

查看:171
本文介绍了创建跨浏览器Gmail扩展程序的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个适用于Chrome和Firefox的Gmail扩展程序。什么是最好的方式进行?

解决方案

只需使用 chrome。* 用于扩展API调用,以编写同时适用的代码。



在很大程度上,Chrome和Firefox(使用 WebExtensions )直接与代码兼容。只要您使用的浏览器支持API( Chrome Firefox ),你可以使用 chrome。 * 两个浏览器中的API调用的命名空间。许多扩展将直接与代码兼容。

但是,有一些功能不兼容。查找有关信息的最佳位置在每个API的Mozilla开发者网络(MDN)页面上。如果您发现不兼容的情况,您可以将它们写出来并将PR提交到浏览器兼容性JSON文件由Mozilla ,或直接修改相应的MDN API页面(例如,开发者需要看到一些东西实际上已经坏了)。对于某些情况,您需要检测您正在运行的浏览器并为每个执行稍微不同的代码。但是,对于大多数情况,这些将是运行时选择。您不应该有两套不同的代码。



Chrome :您应该先阅读 Chrome浏览器扩展程序概述(可能还包括从概述链接的页面)。 体系结构部分具有整体架构信息,这将有助于您理解组织结构/完成。您还应该阅读内容脚本



Firefox :您应该先阅读内容脚本将是非常有益的。
$ b

注意:


  1. 浏览器。* (基于Promise)和 chrome。* (基于回调,如Chrome)。如果您希望在Chrome中使用基于Promise的API调用,Mozilla的 浏览器。 pollyfill 。回调支持 chrome。* 命名空间的事实没有很好的记录(事实上,Mozilla选择将文档更改为仅在几处提到) 。因此,你会发现所有的API页面都显示了浏览器。* 命名空间和Promises。不要被吓倒。支持 chrome。* 命名空间,特别是使用Chrome浏览器进行跨浏览器扩展(特别是从Chrome浏览器到Firefox的移植)更为简单。

  2. b $ b
  3. 每个浏览器都有其他API不支持的API。 Mozilla在开发WebExtensions API方面仍然非常活跃。在很大程度上,这是实现已经在Chrome中可用的API。在某种程度上,这提供了其他类型的Firefox插件中提供的一些附加功能。但是,这将始终是其他类型的Firefox插件可用的功能的一个非常有限的子集。如果您不知道,Firefox将自Firefox 57(2017-11-14)的发布版本起,禁用所有类型的扩展名(非WebExtensions )。




专门用于Gmail



您将需要什么大概取决于您实际上是想要做的。 如何开发适用于Gmail的Chrome扩展?一些信息。您还应该调查 Gmail API 。还有大量的问题/答案与 Gmail谷歌浏览器扩展


I want to create a Gmail extension that should work fine for both Chrome and Firefox. What is the best way to proceed?

解决方案

Just use chrome.* for extension API calls to write code that works in both.

To a large extent, Chrome, and Firefox (using WebExtensions) are directly code compatible. As long as you are using APIs which are supported in both browsers (Chrome, Firefox), you can just use the chrome.* namespace for API calls in both browsers. Many extensions will be directly code compatible.

However, there are some functional incompatibilities. The best place to look for information about such is on the Mozilla Developer Network (MDN) page for each API. If you find incompatibilities, you can write them up and submit a PR to the browser compatibility JSON file maintained by Mozilla, or directly modify the appropriate MDN API page (e.g. issues where developers need to see something is actually broken). For some things, you will need to detect the browser you are running in and execute slightly different code for each. However, for most things these will be runtime choices. You should not need to have two different sets of code.

Chrome: You should begin by reading the Chrome extension overview (perhaps along with the pages linked from the overview). The architecture section has overall architecture information which should help your understanding of how things are generally organized/done. You will should also read Content Scripts.

Firefox: You should begin by reading the Anatomy of a WebExtension page (perhaps work through reading the pages linked from there). It has overall architecture information which should help your understanding of how things are generally organized/done. Here, also, reading about content scripts will be quite beneficial.

Notes:

  1. Firefox natively supports its APIs using both browser.* (Promise based) and chrome.* (callback based, like Chrome). If you want Promise based API calls in Chrome, Mozilla has a browser.* pollyfill. The fact that the chrome.* namespace is supported with callbacks is not well documented (it was, but Mozilla chose to change the docs to only mention it in a couple of places). Thus, you will find all of their API pages showing the browser.* namespace and Promises. Don't be deterred. The chrome.* namespace is supported, specifically to make cross-browser extensions with Chrome (in particular porting from Chrome to Firefox) easier.

  2. Each browser has APIs which are not supported by the other. Mozilla is still very active in developing WebExtensions APIs. To a large extent, this is implementing APIs which are already available in Chrome. To some extent, this is providing some of the additional capability which is available in other types of Firefox add-ons. However, this will always be a very limited subset of the capabilities which are/were available to other types of Firefox add-ons. In case you are unaware, Firefox will disable all types of extensions, other than WebExtensions, as of the release version of Firefox 57 (2017-11-14).

Gmail specifically

What you are going to need will depend greatly on what it is that you are actually wanting to do. There is the question How to develop Chrome extension for Gmail? which provides some information. You should also investigate the Gmail API. There are also a large number of questions/answers related to making a Gmail Google Chrome extension.

这篇关于创建跨浏览器Gmail扩展程序的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆