summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/static/browsingData.html
blob: bd815266c89e0b1c46f207ad7afaa2300fa42bb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<div id="pageData-name" class="pageData">BrowsingData API</div>

<!-- BEGIN AUTHORED CONTENT -->
<p id="classSummary">
  Use the <code>chrome.browsingData</code> module to remove browsing data from a
  user's local profile.
</p>

<h2 id="manifest">Manifest</h2>

<p>
  You must declare the "browsingData" permission in the
  <a href="manifest.html">extension manifest</a> to use this API.
</p>

<pre>{
  "name": "My extension",
  ...
  <b>"permissions": [
    "browsingData",
  ]</b>,
  ...
}</pre>

<h2 id="usage">Usage</h2>

<p>
  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 <code>Date</code> object via the
  <code>getTime</code> method).
</p>

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

<pre>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);</pre>

<p>
  The <code>chrome.browsingData.remove</code> 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.
</p>

<pre>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);</pre>

<p class="caution">
  <strong>Important</strong>: Removing browsing data involves a good deal of
  heavy lifting in the background, and can take <em>tens of seconds</em> 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.
</p>

<h2 id="samples">Examples</h2>
<p>
  Samples for the <code>browsingData</code> API are available
  <a href="http://code.google.com/chrome/extensions/trunk/samples.html#chrome.browsingData">on the samples page</a>.
</p>

<!-- END AUTHORED CONTENT -->