承诺支持Chrome扩展程序API? [英] Promise support for Chrome Extensions API?

查看:145
本文介绍了承诺支持Chrome扩展程序API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在过去几周内一直在编写一些浏览器扩展,直到今天我还认为Firefox的WebExtension应该在Chrome中自动运行。所以我试着根据Mozilla的例子编写我的代码。

但是今天我意识到在Chrome扩展的API文档中没有提到Promises。

我严格使用了Promises在我的所有扩展程序的代码中。

I've been writing some browser extensions in the last few weeks and until today I thought that a WebExtension for Firefox should work pretty much automatically in Chrome. So I tried to write my code according to Mozilla's examples.
But today I realized that there is no mention of Promises in the API documentation for Chrome Extensions.
I have strictly used Promises throughout the code for all my Extensions.

现在我的问题是,我的代码会在Chrome中运行吗?或者,如果我在最顶层添加 var browser = chrome 声明,它会起作用吗?

或者Chrome根本不支持API上的Promises?

如果Chrome还不支持API函数的Promises,它将来是否会支持它们?

So now my question is, will my code work in Chrome? Or would it work if I add a var browser = chrome declaration at the very top?
Or does Chrome not support Promises on the API at all?
If Chrome doesn't support Promises on the API functions yet, will it support them in the future?

注意,我知道这个项目: https://github.com/mozilla/webextension-polyfill

但我不愿意经历在任何地方包括该图书馆的麻烦。此外,它有令人讨厌的错误。

Note, I am aware of this project: https://github.com/mozilla/webextension-polyfill
But I'm not willing to go through the hassle of including that library everywhere. Also, it has annoying bugs in it.

除此之外,我没有Chrome或Chromium,出于隐私和安全原因,我无法安装它们。

And besides that I don't have Chrome or Chromium and I can't install them for privacy and security reasons.

推荐答案


...直到今天我认为Firefox的WebExtension应该在Chrome中自动运行。

...until today I thought that a WebExtension for Firefox should work pretty much automatically in Chrome.

WebExtensions的创建与向后兼容Chrome扩展程序。 chrome。* 命名空间可用于支持的API。这里的目标是简化将现有扩展移植到FF以快速引导生态系统。

WebExtensions were created with backward compatibility with Chrome extensions in mind. chrome.* namespace is available for supported APIs. The goal here is to ease porting existing extensions to FF to quickly bootstrap the ecosystem.

但是,Mozilla忽略了与浏览器的向前兼容性。* 命名空间。 Mozilla决定采用基于承诺的API方法,但只针对新的命名空间。

However, Mozilla disregards forward compatibility with browser.* namespace. Mozilla decided to go with a promise-based approach for the API, but only for that new namespace.


所以现在我的问题是,将我的代码在Chrome中运行?

或者如果我在最顶层添加 var browser = chrome 声明会有效吗?

否;他们的行为不同,有不同的签名。 Chrome会在没有必要的显式回调的情况下拒绝来电。 浏览器。* 变体将发出一个Promise。

No; they behave differently and have different signatures. Chrome will reject calls without required explicit callbacks. browser.* variants will emit a Promise instead.


或Chrome不支持对API的承诺是什么?

如果Chrome还不支持API函数的Promises,它将来是否会支持它们?

Or does Chrome not support Promises on the API at all?
If Chrome doesn't support Promises on the API functions yet, will it support them in the future?

如评论中所述,基于承诺的API重写被Chrome视为 ,但没有做过明显的工作。但是,存在polyfill,包括你提到的那个。除了自己包装方法以创建自己的polyfill之外,没有其他解决方案。

As mentioned in comments, Promise-based rewrite of the API is considered by Chrome, but no visible work has been done. However, there exist polyfills, including the one you mentioned. Other than wrapping methods yourself to create your own polyfill, there's no other solution.


除此之外我还没有Chrome或Chromium出于隐私和安全原因,我无法安装它们。

And besides that I don't have Chrome or Chromium and I can't install them for privacy and security reasons.

然后你无法正确测试你的端口;这对潜在用户来说不是一个好方法。在这种情况下,你最好移植。

Then you can't properly test your ports anyway; that's not a good approach for your potential users. You're better off not porting in this case.

这篇关于承诺支持Chrome扩展程序API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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