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