OLD | NEW |
| (Empty) |
1 <!-- BEGIN AUTHORED CONTENT --> | |
2 <p id="classSummary"> | |
3 Use the <code>chrome.browsingData</code> module to remove browsing data from a | |
4 user's local profile. | |
5 </p> | |
6 <h2 id="manifest">Manifest</h2> | |
7 <p> | |
8 You must declare the "browsingData" permission in the | |
9 <a href="manifest.html">extension manifest</a> to use this API. | |
10 </p> | |
11 <pre>{ | |
12 "name": "My extension", | |
13 ... | |
14 <b>"permissions": [ | |
15 "browsingData", | |
16 ]</b>, | |
17 ... | |
18 }</pre> | |
19 <h2 id="usage">Usage</h2> | |
20 <p> | |
21 The simplest use-case for this API is a a time-based mechanism for clearing a | |
22 user's browsing data. Your code should provide a timestamp which indicates the | |
23 historical date after which the user's browsing data should be removed. This | |
24 timestamp is formatted as the number of milliseconds since the Unix epoch | |
25 (which can be retrieved from a JavaScript <code>Date</code> object via the | |
26 <code>getTime</code> method). | |
27 </p> | |
28 <p> | |
29 For example, to clear all of a user's browsing data from the last week, you | |
30 might write code as follows: | |
31 </p> | |
32 <pre>var callback = function () { | |
33 // Do something clever here once data has been removed. | |
34 }; | |
35 var millisecondsPerWeek = 1000 * 60 * 60 * 24 * 7; | |
36 var oneWeekAgo = (new Date()).getTime() - millisecondsPerWeek; | |
37 chrome.browsingData.remove({ | |
38 "since": oneWeekAgo | |
39 }, { | |
40 "appcache": true, | |
41 "cache": true, | |
42 "cookies": true, | |
43 "downloads": true, | |
44 "fileSystems": true, | |
45 "formData": true, | |
46 "history": true, | |
47 "indexedDB": true, | |
48 "localStorage": true, | |
49 "pluginData": true, | |
50 "passwords": true, | |
51 "webSQL": true | |
52 }, callback);</pre> | |
53 <p> | |
54 The <code>chrome.browsingData.remove</code> method allows you to remove | |
55 various types of browsing data with a single call, and will be much faster | |
56 than calling multiple more specific methods. If, however, you only want to | |
57 clear one specific type of browsing data (cookies, for example), the more | |
58 granular methods offer a readable alternative to a call filled with JSON. | |
59 </p> | |
60 <pre>var callback = function () { | |
61 // Do something clever here once data has been removed. | |
62 }; | |
63 var millisecondsPerWeek = 1000 * 60 * 60 * 24 * 7; | |
64 var oneWeekAgo = (new Date()).getTime() - millisecondsPerWeek; | |
65 chrome.browsingData.removeCookies({ | |
66 "since": oneWeekAgo | |
67 }, callback);</pre> | |
68 <p class="caution"> | |
69 <strong>Important</strong>: Removing browsing data involves a good deal of | |
70 heavy lifting in the background, and can take <em>tens of seconds</em> to | |
71 complete, depending on a user's profile. You should use the callback mechanism | |
72 to keep your users up to date on the removal's status. | |
73 </p> | |
74 <h2 id="origin_types">Origin Types</h2> | |
75 <p> | |
76 Adding an <code>originType</code> property to the API's options object allows | |
77 you to specify which types of origins ought to be effected. Currently, origins | |
78 are divided into three categories: | |
79 </p> | |
80 <ul> | |
81 <li> | |
82 <code>unprotectedWeb</code> covers the general case of websites that users | |
83 visit without taking any special action. If you don't specify an | |
84 <code>originType</code>, the API defaults to removing data from unprotected | |
85 web origins. | |
86 </li> | |
87 <li> | |
88 <code>protectedWeb</code> covers those web origins that have been installed | |
89 as hosted applications. Installing <a href="https://chrome.google.com/websto
re/detail/aknpkdffaafgjchaibgeefbgmgeghloj"> | |
90 Angry Birds</a>, for example, protects the origin | |
91 <code>http://chrome.angrybirds.com</code>, and removes it from the | |
92 <code>unprotectedWeb</code> category. Please do be careful when triggering | |
93 deletion of data for these origins: make sure your users know what they're | |
94 getting, as this will irrevocably remove their game data. No one wants to | |
95 knock tiny pig houses over more often than necessary. | |
96 </li> | |
97 <li> | |
98 <code>extension</code> covers origins under the | |
99 <code>chrome-extensions:</code> scheme. Removing extension data is, again, | |
100 something you should be very careful about. | |
101 </li> | |
102 </ul> | |
103 <p> | |
104 We could adjust the previous example to remove only data from protected | |
105 websites as follows: | |
106 </p> | |
107 <pre>var callback = function () { | |
108 // Do something clever here once data has been removed. | |
109 }; | |
110 var millisecondsPerWeek = 1000 * 60 * 60 * 24 * 7; | |
111 var oneWeekAgo = (new Date()).getTime() - millisecondsPerWeek; | |
112 chrome.browsingData.remove({ | |
113 "since": oneWeekAgo, | |
114 <b>"originType": { | |
115 "protectedWeb": true | |
116 }</b> | |
117 }, { | |
118 "appcache": true, | |
119 "cache": true, | |
120 "cookies": true, | |
121 "downloads": true, | |
122 "fileSystems": true, | |
123 "formData": true, | |
124 "history": true, | |
125 "indexedDB": true, | |
126 "localStorage": true, | |
127 "pluginData": true, | |
128 "passwords": true, | |
129 "webSQL": true | |
130 }, callback);</pre> | |
131 <p class="caution"> | |
132 <strong>Seriously</strong>: Be careful with <code>protectedWeb</code> and | |
133 <code>extension</code>. These are destructive operations that your users | |
134 will write angry email about if they're not well-informed about what to | |
135 expect when your extension removes data on their behalf. | |
136 </p> | |
137 <h2 id="samples">Examples</h2> | |
138 <p> | |
139 Samples for the <code>browsingData</code> API are available | |
140 <a href="http://code.google.com/chrome/extensions/trunk/samples.html#chrome.br
owsingData">on the samples page</a>. | |
141 </p> | |
142 <!-- END AUTHORED CONTENT --> | |
OLD | NEW |