Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

javascript - 创建跨浏览器Gmail扩展的最佳方法是什么? [关闭](What is the best way to create a cross browser Gmail extension? [closed])

I want to create a Gmail extension that should work fine for both Chrome and Firefox.

(我想创建一个Gmail扩展程序,该扩展程序应适用于Chrome和Firefox。)

What is the best way to proceed?

(最好的进行方法是什么?)

  ask by Mohit translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just use chrome.* for extension API calls to write code that works in both.(只需对扩展API调用使用chrome.*即可编写可在两者中均起作用的代码。)

To a large extent, Chrome, and Firefox (using WebExtensions ) are directly code compatible.

(Chrome和Firefox(使用WebExtensions )在很大程度上是直接兼容代码的。)

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.

(只要您使用两个浏览器( ChromeFirefox )都支持的API,就可以在两个浏览器中使用chrome.*名称空间进行API调用。)

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.

(查找有关此类信息的最佳位置是在每个API的Mozilla开发人员网络(MDN)页面上。)

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 (eg issues where developers need to see something is actually broken ).

(如果发现不兼容性,则可以将它们编写并提交PR到Mozilla维护浏览器兼容性JSON文件中 ,或直接修改相应的MDN API页面(例如, 开发人员需要查看实际上已损坏的问题 )。)

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).

(Chrome :您应该先阅读Chrome扩展程序概述 (也许以及概述中链接的页面)。)

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).

(Firefox :您应该先阅读WebExtension页面的剖析 (也许可以通过阅读从此处链接的页面来工作)。)

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).

    (Firefox本身使用browser.* (基于Promise)和chrome.* (基于Chrome等回调)支持其API。)

    If you want Promise based API calls in Chrome, Mozilla has a browser.* pollyfill .

    (如果要在Chrome中基于Promise的API调用,则Mozilla具有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).

    (回调文件支持chrome.*名称空间的事实没有得到很好的记录(事实是,但是Mozilla选择更改文档以仅在几个地方提到它)。)

    Thus, you will find all of their API pages showing the browser.* namespace and Promises.

    (因此,您将找到显示browser.*所有API页面browser.*名称空间和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.

    (支持chrome.*名称空间,特别是使使用Chrome的跨浏览器扩展(特别是从Chrome到Firefox的移植)更加容易。)

  2. Each browser has APIs which are not supported by the other.

    (每种浏览器都有彼此不支持的API。)

    Mozilla is still very active in developing WebExtensions APIs.

    (Mozilla在开发WebExtensions API方面仍然非常活跃。)

    To a large extent, this is implementing APIs which are already available in Chrome.

    (在很大程度上,这是在实现Chrome中已经可用的API。)

    To some extent, this is providing some of the additional capability which is available in other types of Firefox add-ons.

    (在某种程度上,这提供了其他类型的Firefox附加组件中可用的一些附加功能。)

    However, this will always be a very limited subset of the capabilities which are/were available to other types of Firefox add-ons.

    (但是,这将始终是其他类型的Firefox附件可用的功能的非常有限的子集。)

    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).

    (如果您不知道,从Firefox 57(2017-11-14)发行版开始,Firefox将禁用除WebExtensions之外的所有类型的扩展名。)

Gmail specifically(专门用于Gmail)

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?

(问题是如何为Gmail开发Chrome扩展程序?)

which provides some information.

(提供一些信息。)

You should also investigate the Gmail API .

(您还应该调查Gmail API 。)

There are also a large number of questions/answers related to making a Gmail Google Chrome extension .

(还有大量与制作Gmail Google Chrome扩展程序有关的问题/答案。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...