Home | History | Annotate | Download | only in articles
      1 <h1>Autoupdating</h1>
      2 
      3 
      4 <p>We want extensions and apps to be autoupdated for some of the same reasons as Google Chrome itself: to incorporate bug and security fixes, add new features or performance enhancements, and improve user interfaces.</p>
      5 
      6 <p>If you publish using the <a href="https://chrome.google.com/webstore/developer/dashboard">Chrome Developer Dashboard</a>, you can <em>ignore this page</em>. You can use the dashboard to release updated versions to users, as well as to the Chrome Web Store.</p>
      7 
      8 <p>If you want to host somewhere other than the store, keep reading.
      9 You should also read <a href="hosting">Hosting</a> and
     10 <a href="packaging">Packaging</a>.</p>
     11 
     12 <p class="warning"><b>Warning:</b>
     13 As of M33,
     14 Windows stable/beta channel users can only download extensions hosted
     15 in the Chrome Web Store (see
     16 <a href="http://blog.chromium.org/2013/11/protecting-windows-users-from-malicious.html">Protecting Windows users from malicious extensions</a>).
     17 </p>
     18  
     19 <p>
     20 Previously when off-store extensions were supported,
     21 it was possible to have the native binaries and the extension be updated in lock step.
     22 However, extensions hosted on the Chrome Web Store are updated
     23 via the Chrome update mechanism which developers do not control.
     24 Extension developers should be careful about updating extensions
     25 that have a dependency on the native binary
     26 (for example, legacy extensions using <a href="npapi">NPAPI</a>).
     27 </p>
     28 
     29 <h2 id="overview">Overview</h2>
     30 <ul><li>A manifest may contain an "update_url" field, pointing to a location for doing update checks.</li>
     31 <li>The content returned by an update check is an <em>update manifest</em> XML document listing the latest version of an extension.</li></ul>
     32 
     33 <p>Every few hours, the browser checks whether any installed extensions or apps have an update URL. For each one, it makes a request to that URL looking for an update manifest XML file. If the update manifest mentions a version that is more recent than what's installed, the browser downloads and installs the new version. As with manual updates, the new <code>.crx</code> file must be signed with the same private key as the currently installed version.</p>
     34 
     35 
     36 <h2 id="update_url">Update URL</h2>
     37 <p>If you're hosting your own extension or app, you need to add the "update_url" field to your <a href="manifest"><code>manifest.json</code></a> file,
     38 like this:</p>
     39 
     40 <pre data-filename="manifest.json">
     41 {
     42   "name": "My extension",
     43   ...
     44   <b>"update_url": "http://myhost.com/mytestextension/updates.xml"</b>,
     45   ...
     46 }
     47 </pre>
     48 
     49 <h2 id="update_manifest">Update manifest</h2>
     50 <p>The update manifest returned by the server should be an XML document that looks like this (highlights indicate parts you should modify):</p>
     51 
     52 <pre data-filename="updates.xml">
     53 &lt;?xml version='1.0' encoding='UTF-8'?&gt;
     54 &lt;gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'&gt;
     55   &lt;app appid='<b>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</b>'&gt;
     56    &nbsp;&lt;updatecheck&nbsp;codebase='<b>http://myhost.com/mytestextension/mte_v2.crx</b>'&nbsp;version='<b>2.0</b>' /&gt;
     57   &lt;/app&gt;
     58 &lt;/gupdate&gt;
     59 </pre>
     60 
     61 <p>This XML format is borrowed from that used by Omaha, Google's update infrastructure. See <a href="http://code.google.com/p/omaha/">http://code.google.com/p/omaha/</a> for more details.
     62 The extensions system uses the following attributes
     63 for the <strong>&lt;app></strong>
     64 and <strong>&lt;updatecheck></strong> elements of the update manifest:
     65 </p>
     66 
     67 <p><b>appid</b><br>
     68 The extension or app ID, generated based on a hash of the public key,
     69 as described in <a href="packaging">Packaging</a>. You can find the
     70 ID of an extension or Chrome App by going to the Extensions page (<b>chrome://extensions</b>).
     71 </p>
     72 {{?is_apps}}
     73 <p>
     74 Hosted apps, however, are not listed on the Extensions page.  You can find the ID of any
     75 app using the following steps:
     76 </p>
     77 {{/is_apps}}
     78 
     79 {{?is_apps}}
     80 <ul>
     81   <li> Open the app. You can do this by clicking its icon on the New Tab page.</li>
     82   <li> Open the JavaScript console.  You can do this by clicking the wrench icon
     83        and choosing <b>Tools &gt; JavaScript Console</b>.</li>
     84   <li> Enter the following expression into the JavaScript console: <code>chrome.app.getDetails().id</code>
     85       <p>The console shows the app's ID as a quoted string.</p>
     86   </li>
     87 </ul>
     88 {{/is_apps}}
     89 
     90 <p><b>codebase</b><br>
     91 A URL to the <code>.crx</code> file.</p>
     92 
     93 <p><b>version</b><br>
     94 Used by the client to determine whether it should download the <code>.crx</code> file specified by <code>codebase</code>. It should match the value of "version" in the <code>.crx</code> file's <code>manifest.json</code> file.</p>
     95 <p>The update manifest XML file may contain information about multiple extensions by including multiple &lt;app&gt; elements.</p>
     96 
     97 
     98 <h2 id="testing">Testing</h2>
     99 <p>The default update check frequency is several hours,
    100 but you can force an update using the Extensions page's
    101 <b>Update extensions now</b> button.
    102 </p>
    103 
    104 <p>
    105 Another option is to use the --extensions-update-frequency command-line flag to set a more frequent interval in seconds. For example, to make checks run every 45 seconds, run Google Chrome like this:</p>
    106 <pre>
    107 chrome.exe <b>--extensions-update-frequency=45</b></pre>
    108 
    109 <p>Note that this affects checks for all installed extensions and apps, so consider the bandwidth and server load implications of this. You may want to temporarily uninstall all but the one you are testing with, and should not run with this option turned on during normal browser usage.</p>
    110 
    111 
    112 <h2 id="request_parameters">Advanced usage: request parameters</h2>
    113 <p>The basic autoupdate mechanism is designed to make the server-side work as easy as just dropping a static XML file onto any plain web server such as Apache, and updating that XML file as you release new versions of your extensions.</p>
    114 <p>More advanced developers may wish to take advantage of the fact that we add on parameters to the request for the update manifest to indicate the extension ID and version. Then they can use the same update URL for all of their extensions, pointing to a URL running dynamic server-side code instead of a static XML file.</p>
    115 <p>The format of the request parameters is:</p>
    116 <p><code>&nbsp;&nbsp;?x=<em>&lt;extension_data&gt;</em></code></p>
    117 <p>Where <code><em>&lt;extension_data&gt;</em></code> is a URL-encoded string of the format:</p>
    118 <p><code>&nbsp;&nbsp;<em>id=&lt;id&gt;</em>&amp;v=<em>&lt;version&gt;</em></code></p>
    119 
    120 <p>For example, say you have two extensions,
    121 both of which point to the same update URL
    122 (<code>http://test.com/extension_updates.php</code>):
    123 </p>
    124 
    125 <ul>
    126 <li> Extension 1
    127   <ul>
    128     <li> ID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" </li>
    129     <li> Version: "1.1"</li>
    130   </ul>
    131 <li> Extension 2
    132   <ul>
    133     <li> ID: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" </li>
    134     <li> Version: "0.4"</li>
    135   </ul>
    136 </ul>
    137 
    138 
    139 <p>The request to update each individual extension would be:</p>
    140 
    141 <ul>
    142   <li> <code>http://test.com/extension_updates.php?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%26v%3D1.1</code> </li>
    143   <li> <code>http://test.com/extension_updates.php?x=id%3Dbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb%26v%3D0.4</code> </li>
    144 </ul>
    145 
    146 <p>
    147 Multiple extensions can be listed in a single request for each unique update URL.
    148 For the above example, if a user has both of the extensions installed,
    149 then the two requests are merged into a single request:</p>
    150 <p><code>http://test.com/extension_updates.php?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%26v%3D1.1&x=id%3Dbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb%26v%3D0.4</code></p>
    151 
    152 <p>If the number of installed extensions using the same update URL is large enough that a GET request URL is too long (over 2000 characters or so), the update check issues additional GET requests as necessary.</p>
    153 
    154 <p class="note">
    155 <b>Note:</b>
    156 In the future, instead of issuing multiple GET requests,
    157 a single POST request might be issued
    158 with the request parameters in the POST body.
    159 </p>
    160 
    161 <h2 id="minimum_browser_version">Advanced usage: minimum browser version</h2>
    162 <p>As we add more APIs to the extensions system, it's possible you will want to release an updated version of an extension or app that will work only with newer versions of the browser. While Google Chrome itself is autoupdated, it can take a few days before the majority of the user base has updated to any given new release. To ensure that a given update will apply only to Google Chrome versions at or higher than a specific version, you add the "prodversionmin" attribute to the &lt;app&gt; element in your update manifest. For example:</p>
    163 
    164 <pre data-filename="updates.xml">
    165 &lt;?xml version='1.0' encoding='UTF-8'?&gt;
    166 &lt;gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'&gt;
    167 &nbsp;&nbsp;&lt;app appid='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'&gt;
    168 &nbsp;&nbsp; &nbsp;&lt;updatecheck&nbsp;codebase='http://myhost.com/mytestextension/mte_v2.crx'&nbsp;version='2.0' <b>prodversionmin='3.0.193.0'</b>/&gt;
    169 &nbsp;&nbsp;&lt;/app&gt;
    170 &lt;/gupdate&gt;
    171 </pre>
    172 
    173 <p>This would ensure that users would autoupdate to version 2 only if they are running Google Chrome 3.0.193.0 or greater.</p>
    174