Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <div id="pageData-name" class="pageData">Event Pages</div> | 1 <div id="pageData-name" class="pageData">Event Pages</div> |
| 2 <div id="pageData-showTOC" class="pageData">true</div> | 2 <div id="pageData-showTOC" class="pageData">true</div> |
| 3 | 3 |
| 4 <p> | 4 <p> |
| 5 Event pages are very similar to | 5 Event pages are very similar to |
| 6 <a href="background_pages.html">background pages</a>, | 6 <a href="background_pages.html">background pages</a>, |
| 7 with one important difference: | 7 with one important difference: |
| 8 event pages are loaded only when they are needed. | 8 event pages are loaded only when they are needed. |
| 9 When the event page is not actively doing something, | 9 When the event page is not actively doing something, |
| 10 it is unloaded, freeing memory and other system resources. | 10 it is unloaded, freeing memory and other system resources. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 </p> | 58 </p> |
| 59 | 59 |
| 60 <p> | 60 <p> |
| 61 Once the event page has been idle a short time | 61 Once the event page has been idle a short time |
| 62 (a few seconds), the | 62 (a few seconds), the |
| 63 <code><a href="runtime.html#event-onSuspend">chrome.runtime.onSuspend</a></code> | 63 <code><a href="runtime.html#event-onSuspend">chrome.runtime.onSuspend</a></code> |
| 64 event is dispatched. The event page has a few more seconds to handle this | 64 event is dispatched. The event page has a few more seconds to handle this |
| 65 event before it is forcibly unloaded. Note that once the event is dispatched, | 65 event before it is forcibly unloaded. Note that once the event is dispatched, |
| 66 new activity will not keep the event page open. | 66 new activity will not keep the event page open. |
| 67 </p> | 67 </p> |
| 68 | |
| 69 <h2 id="transition">Convert background page to event page</h2> | |
| 70 <p> | |
| 71 Follow this checklist to convert your extension's | |
| 72 (persistent) background page to an event page. | |
| 73 | |
| 74 <ol> | |
| 75 <li>Add <code>"persistent": false</code> to your manifest as shown above. | |
| 76 | |
| 77 <li>Register to receive any events your extension is interested in | |
| 78 each time the event page is loaded. The event page will be loaded once | |
| 79 for each new version of your extension. After that it will only be | |
| 80 loaded to deliver events. | |
|
Aaron Boodman
2012/07/23 23:07:29
.append(" you have registered for") ?
Matt Perry
2012/07/24 00:11:02
Done.
| |
| 81 | |
| 82 <li>If you need to do some initialization when your extension is | |
| 83 installed or upgraded, listen to the | |
| 84 <code><a href="runtime.html#event-onInstalled">chrome.runtime.onInstalled</a>< /code> | |
| 85 event. | |
| 86 | |
| 87 <li>Listen to the | |
| 88 <code><a href="runtime.html#event-onSuspend">chrome.runtime.onSuspend</a></cod e> | |
| 89 event if you need to do last second cleanup before your event page | |
| 90 is shut down. However, we recommend persisting periodically instead. | |
| 91 That way if your extension crashes without receiving | |
| 92 <code>onSuspend</code>, no data will typically be lost. | |
| 93 | |
| 94 <li>If you need to keep runtime state in memory throughout a browser | |
|
Aaron Boodman
2012/07/23 23:07:29
Makes more sense if this point goes before the pre
Matt Perry
2012/07/24 00:11:02
Done.
| |
| 95 session, use the <a href="storage.html">storage API</a> or | |
| 96 IndexedDB. Since the event page does not stay loaded for long, you | |
| 97 can no longer rely on global variables for runtime state. | |
| 98 | |
| 99 <li>If your extension uses <code>window.setTimeout()</code> or | |
| 100 <code>window.setInterval()</code>, switch to using the | |
| 101 <a href="alarms.html">alarms API</a> instead. DOM-based timers won't | |
| 102 be honored if the event page shuts down. | |
| 103 | |
| 104 <li>If your extension uses, | |
| 105 <code><a href="extension.html#method-getBackgroundPage">chrome.extension.getBa ckgroundPage()</a></code>, | |
| 106 switch to | |
| 107 <code><a href="runtime.html#method-getBackgroundPage">chrome.runtime.getBackgr oundPage()</a></code> | |
| 108 instead. | |
|
Aaron Boodman
2012/07/23 23:07:29
.append(" The newer method is asynchronous so that
Matt Perry
2012/07/24 00:11:02
Done.
| |
| 109 | |
| 110 <li>If you're using <a href="messaging.html">message passing</a>, be sure | |
| 111 to close unused message ports. The event page will not shut down until all | |
| 112 message ports are closed. | |
| 113 </ol> | |
| 114 </p> | |
| OLD | NEW |