Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the BSD License.
©2012 Google
Use the chrome.privacy
module to control usage of the features in
Chrome that can affect a user's privacy. This module relies on the
ChromeSetting prototype of the type API
for getting and setting Chrome's configuration.
The Chrome Privacy Whitepaper gives background detail regarding the features which this API can control.
You must declare the "privacy" permission in your extension's manifest to use the API. For example:
{ "name": "My extension", ... "permissions": [ "privacy" ], ... }
Reading the current value of a Chrome setting is straightforward. You'll first
need to find the property you're interested in, then you'll call
get()
on that object in order to retrieve its current value and
your extension's level of control. For example, to determine if Chrome's
Autofill feature is enabled, you'd write:
chrome.privacy.services.autofillEnabled.get({}, function(details) { if (details.value) console.log('Autofill is on!'); else console.log('Autofill is off!'); });
Changing the value of a setting is a little bit more complex, simply because
you first must verify that your extension can control the setting. The user
won't see any change to her settings if your extension toggles a setting that
is either locked to a specific value by enterprise policies
(levelOfControl
will be set to "not_controllable"), or if another
extension is controlling the value (levelOfControl
will be set to
"controlled_by_other_extensions"). The set()
call will succeed,
but the setting will be immediately overridden. As this might be confusing, it
is advisable to warn the user when the settings they've chosen aren't
practically applied.
Full details about extensions' ability to control ChromeSetting
s
can be found under
chrome.types.ChromeSetting
.
This means that you ought to use the get()
method to determine
your level of access, and then only call set()
if your extension
can grab control over the setting (in fact if your extension can't control the
setting it's probably a good idea to visually disable the functionality to
reduce user confusion):
chrome.privacy.services.autofillEnabled.get({}, function(details) { if (details.levelOfControl === 'controllable_by_this_extension') { chrome.privacy.services.autofillEnabled.set({ value: true }, function() { if (chrome.extension.lastError === undefined) console.log("Hooray, it worked!"); else console.log("Sadness!", chrome.extension.lastError); } } });
If you're interested in changes to a setting's value, add a listener to its
onChange
event. Among other uses, this will allow you to warn the
user if a more recently installed extension grabs control of a setting, or if
enterprise policy overrides your control. To listen for changes to Autofill's
status, for example, the following code would suffice:
chrome.privacy.services.autofillEnabled.onChange.addListener( function (details) { // The new value is stored in `details.value`, the new level of control // in `details.levelOfControl`, and `details.incognitoSpecific` will be // `true` if the value is specific to Incognito mode. });
For example code, see the Privacy API samples.
Use the chrome.privacy
module to control usage of the features in
Chrome that can affect a user's privacy. This module relies on the
ChromeSetting prototype of the type API
for getting and setting Chrome's configuration.
The Chrome Privacy Whitepaper gives background detail regarding the features which this API can control.
You must declare the "privacy" permission in your extension's manifest to use the API. For example:
{ "name": "My extension", ... "permissions": [ "privacy" ], ... }
Reading the current value of a Chrome setting is straightforward. You'll first
need to find the property you're interested in, then you'll call
get()
on that object in order to retrieve its current value and
your extension's level of control. For example, to determine if Chrome's
Autofill feature is enabled, you'd write:
chrome.privacy.services.autofillEnabled.get({}, function(details) { if (details.value) console.log('Autofill is on!'); else console.log('Autofill is off!'); });
Changing the value of a setting is a little bit more complex, simply because
you first must verify that your extension can control the setting. The user
won't see any change to her settings if you extension toggles a setting that
is either locked to a specific value by enterprise policies
(levelOfControl
will be set to "not_controllable"), or if another
extension is controlling the value (levelOfControl
will be set to
"controlled_by_other_extensions"). The set()
call will succeed,
but the setting will be immediately overridden. As this might be confusing, it
is advisable to warn the user when the settings they've chosen aren't
practically applied.
Full details about extensions' ability to control ChromeSetting
s
can be found under
chrome.types.ChromeSetting
.
This means that you ought to use the get()
method to determine
your level of access, and then only call set()
if your extension
can grab control over the setting (in fact if your extension can't control the
setting it's probably a good idea to visibly disable the functionality to
reduce user confusion):
chrome.privacy.services.autofillEnabled.get({}, function(details) { if (details.levelOfControl === 'controllable_by_this_extension') { chrome.privacy.services.autofillEnabled.set({ value: true }, function() { if (chrome.extension.lastError === undefined) console.log("Hooray, it worked!"); else console.log("Sadness!", chrome.extension.lastError); } } });
If you're interested in changes to a setting's value, add a listener to its
onChange
event. Among other uses, this will allow you to warn the
user if a more recently installed extension grabs control of a setting, or if
enterprise policy overrides your control. To listen for changes to Autofill's
status, for example, the following code would suffice:
chrome.privacy.services.autofillEnabled.onChange.addListener( function (details) { // The new value is stored in `details.value`, the new level of control // in `details.levelOfControl`, and `details.incognitoSpecific` will be // `true` if the value is specific to Incognito mode. });
For example code, see the Privacy API samples.
<link rel='prefetch' ...>
), and preemptively opening TCP and SSL connections to servers. This preference's value is a boolean, defaulting to true
.
true
.
true
.
true
.
true
.
true
.
false
.
true
.
true
.
<a ping>
). The value of this preference is of type boolean, and the default value is true
.
referer
headers with your requests. Yes, the name of this preference doesn't match the misspelled header. No, we're not going to change it. The value of this preference is of type boolean, and the default value is true
.
true
.