Description
Use the chrome.browsingData API to remove browsing data from a user's local profile.
Permissions
browsingDataManifest
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,
  "cacheStorage": true,
  "cookies": true,
  "downloads": true,
  "fileSystems": true,
  "formData": true,
  "history": true,
  "indexedDB": true,
  "localStorage": true,
  "passwords": true,
  "serviceWorkers": 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);
If the user is syncing their data, chrome.browsingData.remove may automatically rebuild the cookie
for the Sync account after clearing it. This is to ensure that Sync can continue working, so that
the data can be eventually deleted on the server. However the more specific
chrome.browsingData.removeCookies can be used to clear the cookie for the Sync account, and Sync
will be paused in this case.
Specific Origins
To remove data for a specific origin or to exclude a set of origins from deletion, you can use the
RemovalOptions.origins and RemovalOptions.excludeOrigins parameters. They can only be applied to
cookies, cache, and storage (CacheStorage, FileSystems, IndexedDB, LocalStorage, ServiceWorkers, and
WebSQL).
chrome.browsingData.remove({
  "origins": ["https://www.example.com"]
}, {
  "cacheStorage": true,
  "cookies": true,
  "fileSystems": true,
  "indexedDB": true,
  "localStorage": true,
  "serviceWorkers": true,
  "webSQL": true
}, callback);
Origin Types
Adding an originTypes property to the API's options object allows you to specify which types of
origins ought to be effected. Currently, origins are divided into three categories:
- unprotectedWebcovers the general case of websites that users visit without taking any special action. If you don't specify an- originTypes, the API defaults to removing data from unprotected web origins.
- protectedWebcovers those web origins that have been installed as hosted applications. Installing Angry Birds, for example, protects the origin- https://chrome.angrybirds.com, and removes it from the- unprotectedWebcategory. Please do be careful when triggering deletion of data for these origins: make sure your users know what they're getting, as this will irrevocably remove their game data. No one wants to knock tiny pig houses over more often than necessary.
- extensioncovers origins under the- chrome-extensions:scheme. Removing extension data is, again, something you should be very careful about.
We could adjust the previous example to remove only data from protected websites 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,
  "originTypes": {
    "protectedWeb": true
  }
}, {
  "appcache": true,
  "cache": true,
  "cacheStorage": true,
  "cookies": true,
  "downloads": true,
  "fileSystems": true,
  "formData": true,
  "history": true,
  "indexedDB": true,
  "localStorage": true,
  "passwords": true,
  "serviceWorkers": true,
  "webSQL": true
}, callback);
Examples
To try this API, install the browsingData API example from the chrome-extension-samples repository.
Types
DataTypeSet
A set of data types. Missing data types are interpreted as false.
Properties
- 
    appcacheboolean optional Websites' appcaches. 
- 
    cacheboolean optional The browser's cache. 
- 
    cacheStorageboolean optional Chrome 72+Cache storage 
- 
    cookiesboolean optional The browser's cookies. 
- 
    downloadsboolean optional The browser's download list. 
- 
    fileSystemsboolean optional Websites' file systems. 
- 
    formDataboolean optional The browser's stored form data. 
- 
    historyboolean optional The browser's history. 
- 
    indexedDBboolean optional Websites' IndexedDB data. 
- 
    localStorageboolean optional Websites' local storage data. 
- 
    passwordsboolean optional Stored passwords. 
- 
    pluginDataboolean optional Deprecated since Chrome 88Support for Flash has been removed. This data type will be ignored. Plugins' data. 
- 
    serverBoundCertificatesboolean optional Deprecated since Chrome 76Support for server-bound certificates has been removed. This data type will be ignored. Server-bound certificates. 
- 
    serviceWorkersboolean optional Service Workers. 
- 
    webSQLboolean optional Websites' WebSQL data. 
RemovalOptions
Options that determine exactly what data will be removed.
Properties
- 
    excludeOriginsstring[] optional Chrome 74+When present, data for origins in this list is excluded from deletion. Can't be used together with origins. Only supported for cookies, storage and cache. Cookies are excluded for the whole registrable domain.
- 
    originTypesobject optional An object whose properties specify which origin types ought to be cleared. If this object isn't specified, it defaults to clearing only "unprotected" origins. Please ensure that you really want to remove application data before adding 'protectedWeb' or 'extensions'. - 
    extensionboolean optional Extensions and packaged applications a user has installed (be _really_ careful!). 
- 
    protectedWebboolean optional Websites that have been installed as hosted applications (be careful!). 
- 
    unprotectedWebboolean optional Normal websites. 
 
- 
    
- 
    origins[string, ...string[]] optional Chrome 74+When present, only data for origins in this list is deleted. Only supported for cookies, storage and cache. Cookies are cleared for the whole registrable domain. 
- 
    sincenumber optional Remove data accumulated on or after this date, represented in milliseconds since the epoch (accessible via the getTimemethod of the JavaScriptDateobject). If absent, defaults to 0 (which would remove all browsing data).
Methods
remove()
chrome.browsingData.remove(
options: RemovalOptions,
dataToRemove: DataTypeSet,
callback?: function,
): Promise<void>
Clears various types of browsing data stored in a user's profile.
Parameters
- 
    options
- 
    dataToRemoveThe set of data types to remove. 
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeAppcache()
chrome.browsingData.removeAppcache(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears websites' appcache data.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeCache()
chrome.browsingData.removeCache(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears the browser's cache.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeCacheStorage()
chrome.browsingData.removeCacheStorage(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears websites' cache storage data.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeCookies()
chrome.browsingData.removeCookies(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears the browser's cookies and server-bound certificates modified within a particular timeframe.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeDownloads()
chrome.browsingData.removeDownloads(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears the browser's list of downloaded files (not the downloaded files themselves).
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeFileSystems()
chrome.browsingData.removeFileSystems(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears websites' file system data.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeFormData()
chrome.browsingData.removeFormData(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears the browser's stored form data (autofill).
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeHistory()
chrome.browsingData.removeHistory(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears the browser's history.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeIndexedDB()
chrome.browsingData.removeIndexedDB(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears websites' IndexedDB data.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeLocalStorage()
chrome.browsingData.removeLocalStorage(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears websites' local storage data.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removePasswords()
chrome.browsingData.removePasswords(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears the browser's stored passwords.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removePluginData()
chrome.browsingData.removePluginData(
options: RemovalOptions,
callback?: function,
): Promise<void>
Support for Flash has been removed. This function has no effect.
Clears plugins' data.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeServiceWorkers()
chrome.browsingData.removeServiceWorkers(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears websites' service workers.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeWebSQL()
chrome.browsingData.removeWebSQL(
options: RemovalOptions,
callback?: function,
): Promise<void>
Clears websites' WebSQL data.
Parameters
- 
    options
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
settings()
chrome.browsingData.settings(
callback?: function,
): Promise<object>
Reports which types of data are currently selected in the 'Clear browsing data' settings UI. Note: some of the data types included in this API are not available in the settings UI, and some UI settings control more than one data type listed here.
Parameters
- 
    callbackfunction optional The callbackparameter looks like:(result: object) => void - 
    resultobject - 
    dataRemovalPermittedAll of the types will be present in the result, with values of trueif they are permitted to be removed (e.g., by enterprise policy) andfalseif not.
- 
    dataToRemoveAll of the types will be present in the result, with values of trueif they are both selected to be removed and permitted to be removed, otherwisefalse.
- 
    options
 
- 
    
 
- 
    
Returns
- 
            Promise<object> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.