You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files.
WARNING: This is the BETA documentation. It may not work with the stable release of Chrome.
WARNING: This is unofficial documentation. It may not work with the current release of Chrome.

Google Chrome Extensions (Labs)

BrowsingData API

BrowsingData API

Use the chrome.browsingData module to remove browsing data from a user's local profile.

Manifest

You must declare the "browsingData" permission in the extension manifest to use this API.

{
  "name": "My extension",
  ...
  "permissions": [
    "browsingData",
  ],
  ...
}

Usage

The simplest use-case for this API is a a time-based mechanism for clearing a user's browsing data. Your code should provide a timestamp which indicates the historical date after which the user's browsing data should be removed. This timestamp is formatted as the number of milliseconds since the Unix epoch (which can be retrieved from a JavaScript Date object via the getTime method).

For example, to clear all of a user's browsing data from the last week, you might write code as follows:

var callback = function () {
  // Do something clever here once data has been removed.
};
var millisecondsPerWeek = 1000 * 60 * 60 * 24 * 7;
var oneWeekAgo = (new Date()).getTime() - millisecondsPerWeek;
chrome.browsingData.remove({
  "since": oneWeekAgo
}, {
  "appcache": true,
  "cache": true,
  "cookies": true,
  "downloads": true,
  "fileSystems": true,
  "formData": true,
  "history": true,
  "indexedDB": true,
  "localStorage": true,
  "pluginData": true,
  "passwords": true,
  "webSQL": true
}, callback);

The chrome.browsingData.remove method allows you to remove various types of browsing data with a single call, and will be much faster than calling multiple more specific methods. If, however, you only want to clear one specific type of browsing data (cookies, for example), the more granular methods offer a readable alternative to a call filled with JSON.

var callback = function () {
  // Do something clever here once data has been removed.
};
var millisecondsPerWeek = 1000 * 60 * 60 * 24 * 7;
var oneWeekAgo = (new Date()).getTime() - millisecondsPerWeek;
chrome.browsingData.removeCookies({
  "since": oneWeekAgo
}, callback);

Important: Removing browsing data involves a good deal of heavy lifting in the background, and can take tens of seconds to complete, depending on a user's profile. You should use the callback mechanism to keep your users up to date on the removal's status.

Examples

Samples for the browsingData API are available on the samples page.

API reference: chrome.browsingData

Methods

remove

chrome.browsingData.remove(RemovalOptions options, object dataToRemove, function callback)

Clears various types of browsing data stored in a user's profile.

Parameters

options
Undocumented.
dataToRemove
( object )
An object whose properties specify which browsing data types ought to be cleared. You may set as many or as few as you like in a single call, each is optional (defaulting to false).
appcache
( optional boolean )
Should websites' appcaches be cleared?
cache
( optional boolean )
Should the browser's cache be cleared? Note: this clears the entire cache: it is not limited to the range you specify.
cookies
( optional boolean )
Should the browser's cookies be cleared?
downloads
( optional boolean )
Should the browser's download list be cleared?
fileSystems
( optional boolean )
Should websites' file systems be cleared?
formData
( optional boolean )
Should the browser's stored form data be cleared?
history
( optional boolean )
Should the browser's history be cleared?
indexedDB
( optional boolean )
Should websites' IndexedDB data be cleared?
localStorage
( optional boolean )
Should websites' local storage data be cleared?
serverBoundCertificates
( optional boolean )
Should server-bound certificates be removed?
pluginData
( optional boolean )
Should plugins' data be cleared?
passwords
( optional boolean )
Should the stored passwords be cleared?
webSQL
( optional boolean )
Should websites' WebSQL data be cleared?
callback
( optional function )
Called when deletion has completed.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeAppcache

chrome.browsingData.removeAppcache(RemovalOptions options, function callback)

Clears websites' appcache data.

Parameters

options
Undocumented.
callback
( optional function )
Called when websites' appcache data has been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeCache

chrome.browsingData.removeCache(RemovalOptions options, function callback)

Clears the browser's cache.

Parameters

options
Undocumented.
callback
( optional function )
Called when the browser's cache has been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeCookies

chrome.browsingData.removeCookies(RemovalOptions options, function callback)

Clears the browser's cookies modified within a particular timeframe.

Parameters

options
Undocumented.
callback
( optional function )
Called when the browser's cookies have been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeDownloads

chrome.browsingData.removeDownloads(RemovalOptions options, function callback)

Clears the browser's list of downloaded files (not the downloaded files themselves).

Parameters

options
Undocumented.
callback
( optional function )
Called when the browser's list of downloaded files has been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeFileSystems

chrome.browsingData.removeFileSystems(RemovalOptions options, function callback)

Clears websites' file system data.

Parameters

options
Undocumented.
callback
( optional function )
Called when websites' file systems have been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeFormData

chrome.browsingData.removeFormData(RemovalOptions options, function callback)

Clears the browser's stored form data (autofill).

Parameters

options
Undocumented.
callback
( optional function )
Called when the browser's form data has been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeHistory

chrome.browsingData.removeHistory(RemovalOptions options, function callback)

Clears the browser's history.

Parameters

options
Undocumented.
callback
( optional function )
Called when the browser's history has cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeIndexedDB

chrome.browsingData.removeIndexedDB(RemovalOptions options, function callback)

Clears websites' IndexedDB data.

Parameters

options
Undocumented.
callback
( optional function )
Called when websites' IndexedDB data has been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeLocalStorage

chrome.browsingData.removeLocalStorage(RemovalOptions options, function callback)

Clears websites' local storage data.

Parameters

options
Undocumented.
callback
( optional function )
Called when websites' local storage has been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removePasswords

chrome.browsingData.removePasswords(RemovalOptions options, function callback)

Clears the browser's stored passwords.

Parameters

options
Undocumented.
callback
( optional function )
Called when the browser's passwords have been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removePluginData

chrome.browsingData.removePluginData(RemovalOptions options, function callback)

Clears plugins' data.

Parameters

options
Undocumented.
callback
( optional function )
Called when plugins' data has been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

removeWebSQL

chrome.browsingData.removeWebSQL(RemovalOptions options, function callback)

Clears websites' WebSQL data.

Parameters

options
Undocumented.
callback
( optional function )
Called when websites' WebSQL databases have been cleared.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

Types

RemovalOptions

( object )
Options that determine exactly what data will be removed.
since
( optional number )
Remove data accumulated on or after this date, represented in milliseconds since the epoch (accessible via the getTime method of the JavaScript Date object). If absent, defaults to 0 (which would remove all browsing data).