The chrome.experimental.managedMode
module allows extensions to
request that the browser enter managed mode, as well as to query whether it
is currently in managed mode.
Note: Extensions cannot request that the browser leave managed mode. This must be done by the user from within the browser itself.
You must declare the "managedMode" and "experimental" permissions in your extension's manifest to use the API. For example:
{ "name": "My extension", ... "permissions": [ "experimental", "managedMode" ], ... }
Managed mode allows one person to manage the Chrome experience for another person by pre-configuring and then locking a managed User profile. For more information about Chrome's managed mode, see [TBD].
Querying managed mode is straightforward. Simply call get()
,
providing a callback function to receive the result. For example:
chrome.experimental.managedMode.get(function(details) { if (details.value) console.log('Managed mode is on.'); else console.log('Managed mode is off.'); });
Entering managed mode is a little bit more complex, because if the browser is
already in managed mode, trying to enter it again will have no effect. To
avoid confusing users, it's advisable to check whether your extension can
enter managed mode (i.e., if it is not already in effect), and visually
disable the functionality in your extension if not. You can optionally
provide a callback function to enter()
to receive the result.
For example:
chrome.experimental.managedMode.get(function(details) { if (details.value) { console.log("Managed mode is already in effect."); } else { chrome.experimental.managedMode.enter(function(result) { if (chrome.extension.lastError === undefined) { if (result.success) console.log("Hooray, it worked!"); else console.log("Oops, the user changed her mind."); } else { console.log("Aw, snap!", chrome.extension.lastError); } }); } });