Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - 使用chrome.tabs与browser.tabs来实现浏览器兼容性(Using chrome.tabs vs browser.tabs for browser compatibility)

I'm porting my Chrome extension to Firefox.

(我正在将Chrome扩展程序移植到Firefox。)

According to MDN there is a browser.tabs API which should be supported by chrome.

(根据MDN,有chrome应该支持的browser.tabs API。)

However browser is not an object in Chrome stable.

(但是, browser不是Chrome稳定版中的对象。)

At the same time chrome.tabs works just fine in Firefox.

(同时chrome.tabs在Firefox中可以正常工作。)

Is it safe to replace browser with chrome when reading the MDN docs?

(在阅读MDN文档时,用chrome替换browser是否安全?)

What is the reason for the docs to write browser ?

(文档编写browser的原因是什么?)

Is there are planned change coming?

(有计划的变更吗?)

  ask by hultqvist translate from so

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

1 Reply

0 votes
by (71.8m points)

Note: In the last couple days, many of the MDN JavaScript API pages have been changed from using chrome.* to using browser.* and describing the promise which is provided by the browser.* interface.

(注意:最近几天,许多MDN JavaScript API页面已从使用chrome.*更改为使用browser.*并描述了由browser.*界面提供的承诺。)

Those changes make the pages not mention using the API as chrome.* at all.

(这些更改使页面根本没有提及使用API??作为chrome.*的页面。)

The changes are being made by the same person within the project with whom I had discussed the change away from browser.* to chrome.* .

(所做的更改是由项目讨论中的同一个人进行的,与我讨论过的从browser.*更改为chrome.*的更改相同。)

I do not yet know what is going on.

(我还不知道发生了什么。)

I have sent him email asking the reason for those changes.

(我已向他发送电子邮件询问这些更改的原因。)

As of this edit, 2016-11-02, it is too soon to expect a response from him.

(截至2016年11月2日编辑,现在期待他的回应还为时过早。)


I am not involved with working on the API.

(我没有参与API的开发。)

But, I have made, and will make, some changes to the API documentation specifically in respect to WebExtensions chrome.* vs. browser.* (all pages were changed to show chrome.* as of 2016-09-22).

(但是,我已经并且将对API文档进行一些更改,特别是关于WebExtensions chrome.*browser.*更改(截至2016-09-22,所有页面都更改为显示chrome.* )。)

I got involved because I, also, found having most of the WebExtensions API pages show browser.* confusing.

(我之所以参与其中,是因为我也发现大多数WebExtensions API页面都显示了browser.*令人困惑。)

I wanted to know what the difference was between chrome.* and browser.* .

(我想知道chrome.*browser.*之间的区别是什么。)

Once I found out, I wanted to make it less confusing for others.

(一旦发现,我想让其他人减少混乱。)

The WebExtensions browser.* API returns a promise :(WebExtensions browser.* API返回promise :)

The browser.* object implements a version of the API that returns a promise if you omit providing a callback function when you call the API.

(browser.*对象实现了API的版本, 如果您在调用API时忽略提供回调函数该API会返回诺言 。)

The intent is that the actual functionality is the same for both chrome.* and browser.* .

(目的是chrome.*browser.*的实际功能相同。)

If you provide a callback function to the browser.* API, it functions identically to the chrome.* API.

(如果您为browser.* API提供了回调函数,则其功能与chrome.* API相同。)

Is it safe to replace browser with chrome when reading the MDN docs?

(在阅读MDN文档时,用chrome替换browser是否安全?)

Yes, unless the documentation is specifically discussing promises.

(是的,除非文档专门讨论了承诺。)

The only difference between the two is that the browser.* methods will return a promise if the callback function is not provided when you call the API.

(两者之间的唯一区别是,如果在调用API时未提供回调函数,则browser.*方法将返回promise。)

What is the reason for the docs to write browser ?

(文档编写browser的原因是什么?)

I'm not sure as to why the docs were originally written with browser.* being so prominent.

(我不知道为什么文档最初是用browser.*编写的browser.* 。)

I assume that either it was a configuration choice that was made when the pages were generated, or the specifics of the difference between chrome.* and browser.* changed at some point early in implementing the WebExtensions API.

(我假设这是在生成页面时做出的配置选择,还是在实施WebExtensions API的某个时候更改了chrome.*browser.*之间的区别的细节。)

Is there a technical reason why chrome.* without a callback can't return a promise?

(chrome.*没有回调就不能返回诺言有技术上的原因吗?)

The only reason I have come up with so far is that using chrome.* to return promises would make it impossible to check for the presence of a mandatory callback function when performing parameter checking within the API.

(到目前为止,我想出的唯一原因是使用chrome.*返回promise将使得在API中执行参数检查时无法检查是否存在强制回调函数。)

With the browser.* namespace, the API can assume the caller is using the returned promise.

(使用browser.*名称空间,API可以假定调用者正在使用返回的Promise。)

Thus, with browser.* a promise can be returned rather than generating an error when a mandatory callback function is not provided in the call to the API.

(因此,使用browser.*当在API的调用中未提供强制回调函数时,可以返回承诺而不是生成错误。)

This reason is, however, speculation on my part.

(但是,这是我的推测。)

Changing the documentation:(更改文档:)

I agree that having the API documentation primarily show browser.* in the Syntax section and elsewhere in each API page is confusing (eg in examples).

(我同意让API文档主要在“语法”部分以及每个API页面的其他地方显示browser.*令人困惑(例如,在示例中)。)

I have been discussing changing this across the entire API documentation with the person primarily in charge of the WebExtensions documentation for the last 3 weeks.

(最近三周,我一直在与主要负责WebExtensions文档的人员讨论在整个API文档中进行此更改。)

He agrees that it should be changed.

(他同意应对此进行更改。)

There are plans to make the change.

(有计划进行更改。)

The documentation will change in at least two phases.

(文档将至少分为两个阶段。)

The first will be to go through all the WebExtensions API pages and change the Syntax section to say chrome.* .

(首先是浏览所有WebExtensions API页面,并将“语法”部分更改为chrome.* 。)

A note at the end of the Syntax section will say that the "API is also available as browser.* in a version that returns a promise ."

(在“语法”部分末尾的注释中会说:“ API也可以作为browser.*返回promise版本中 。”)

In addition, all usage of browser.* throughout the page will be changed to chrome.* except those portions which are specifically showing the API being used as returning a promise.

(此外,整个页面中所有browser.*用法都将更改为chrome.*但那些专门显示API用作返回承诺的部分除外。)

The current expectation is that the page will look much like alarms.clear() does now.

(当前的期望是该页面看起来非常类似于alarms.clear()现在。)

I had changed that page to show what I was suggesting the change will be, including suggestions from the person in charge of the WebExtensions documentation.

(我已经更改了该页面以显示我所建议的更改,包括WebExtensions文档负责人的建议。)

The alarms.clear() Syntax section currently looks like:

(目前, alarms.clear()语法部分如下所示:)

具有新格式的alarms.clear()

Initially (3 weeks ago, 2016-08-25), I had changed the API pages from alarms.clear() through browserAction.enable() with the primary change of moving the content from saying browser.* to chrome.* when my access to making changes on MDN was disabled due to their automatic SPAM filtering.

(最初(3周前,2016-08-25),我将API页面从alarms.clear()更改为browserAction.enable() ,主要更改是将内容从说browser.*更改为chrome.*由于其自动进行SPAM过滤,因此无法访问MDN上的更改。)

This lead to the discussion of the format that the changes will take.

(这导致讨论更改的格式。)

I paused making changes with the hope that making the initial changes could be done in one pass once the intermediate format for the Syntax box was chosen.<b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...