tabs.hide() 编辑

Hides one or more tabs.

Hidden tabs are no longer visible in the browser's tabstrip. Hidden tabs are not automatically discarded: the code running in them continues to run. You can explicitly discard tabs whenever you hide them: although this is not appropriate in all situations, it will help to reduce the resources used by the browser.

This is an asynchronous function that returns a Promise.

Not all tabs are eligible for being hidden:

  • Tabs that are pinned cannot be hidden.
  • Tabs that are sharing the screen, microphone or camera cannot be hidden.
  • The current active tab cannot be hidden.
  • Tabs that are in the process of being closed cannot be hidden.

The first time an extension hides a tab, the browser will tell the user that the tab is being hidden, show them how they can access the hidden tab, and give them the option of disabling the extension instead.

To use this API you must have the "tabHide" permission.

Syntax

var hiding = browser.tabs.hide(
  tabIds          // integer or integer array
)

Parameters

tabIds
integer or array of integer. The IDs of the tab or tabs to hide.
If any of these tabs are not eligible for being hidden, they will not be hidden, but the call will still succeed and eligible tabs will still be hidden. For example, if you pass [1, 3], and 1 identifies the active tab, then only 3 will be hidden.
However, if any of the tab IDs are invalid, the call will fail and no tabs will be hidden.

Return value

A Promise that will be fulfilled with an array containing the IDs of the tabs that were hidden. If any error occurs, the promise will be rejected with an error message.

Examples

Hide a single tab:

function onHidden() {
  console.log(`Hidden`);
}

function onError(error) {
  console.log(`Error: ${error}`);
}

browser.tabs.hide(2).then(onHidden, onError);

Hide multiple tabs:

function onHidden() {
  console.log(`Hidden`);
}

function onError(error) {
  console.log(`Error: ${error}`);
}

browser.tabs.hide([15, 14, 1]).then(onHidden, onError);

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:55 次

字数:3293

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文