使用
BrowserSetting.set()
to change the browser setting to a new value.
There are some rules that can restrict when extensions are able to change settings:
This means that if extension X tries to change a setting:
An extension can find out which of these scenarios applies by examining the "
levelOfControl
" property returned from a call to
BrowserSetting.get()
.
The
BrowserSetting.set()
method returns a Promise that resolves to a boolean: if an attempt to change a setting actually results in the setting being changed (scenarios 2 and 3 above) the boolean is
true
: otherwise it is
false
.
var setting = setting.set(
details
// object
)
details
An object that must contain the following property:
value
any
. The value you want to change the setting to. Its type depends on the particular setting.
A
Promise
that will be fulfilled with a
boolean
:
true
if the setting was modified,
false
otherwise (for example, because the extension did not control the setting).
Modify the
hyperlinkAuditingEnabled
setting (this requires the "privacy" permission):
function onSet(result) {
if (result) {
console.log("Value was updated");
} else {
console.log("Value was not updated");
}
}
browser.browserAction.onClicked.addListener(() => {
var setting = browser.privacy.websites.hyperlinkAuditingEnabled.set({
value: false
});
setting.then(onSet);
});
注意:
This API is based on Chromium's
chrome.types
API。
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.
最后修改: , 由 MDN 贡献者