browserAction.getBadgeBackgroundColor()

获取浏览器操作徽章的背景颜色。

这是一个返回 Promise 的异步函数。

语法

js
browser.browserAction.getBadgeBackgroundColor(
  details // 对象
)

参数

details

包含以下属性的对象:

tabId 可选

integer。指定从中获取徽章背景颜色的标签页。

windowId 可选

integer。指定从中获取徽章背景颜色的窗口。

  • 如果同时提供了 windowIdtabId,则函数失败。
  • 如果 windowIdtabId 都省略,则返回全局徽章背景颜色。

返回值

一个 Promise,其会兑现一个包含了检索到的颜色的 browserAction.ColorArray

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
getBadgeBackgroundColor
details.windowId parameter

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support

示例

记录徽章的背景颜色:

js
function onGot(color) {
  console.log(color);
}

function onFailure(error) {
  console.log(error);
}

browser.browserAction.getBadgeBackgroundColor({}).then(onGot, onFailure);

备注: 此 API 基于 Chromium 的 chrome.browserAction API。该文档衍生自 Chromium 代码中的 browser_action.json