summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/static/event_pages.html
blob: b980809eaea370db93b166af78237eceb36b37dc (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
<div id="pageData-name" class="pageData">Event Pages</div>
<div id="pageData-showTOC" class="pageData">true</div>

<p class="warning">
  <!-- Standard content lead-in for APIs that are not yet available on
  the stable channel. -->
  <em>Warning:</em> This API is still under development. It is only
  available for Chrome users on the
  <span>
    <strong>dev</strong>
      <a href="http://www.chromium.org/getting-involved/dev-channel">early
      release channel</a>.</span>
</p>

<p>
Event pages are very similar to
<a href="background_pages.html">background pages</a>,
with one important difference:
event pages are loaded only when they are needed.
When the event page is not actively doing something,
it is unloaded, freeing memory and other system resources.
</p>

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

<p>
Register your event page in the
<a href="manifest.html">extension manifest</a>:
</p>

<pre>{
  "name": "My extension",
  ...
  <b>"background": {
    "scripts": ["eventPage.js"],
    "persistent": false
  }</b>,
  ...
}</pre>

<p>
Notice that without the "persistent" key, you have
a regular background page. Persistence is what differentiates
an event page from a background page.
</p>

<h2 id="lifetime">Lifetime</h2>

<p>
The event page is loaded when it is "needed", and unloaded
when it goes idle again. Here are some examples of things
that will cause the event page to load:
</p>
<ul>
<li>The extension is first installed.
<li>The event page listens for an event and the event is dispatched.
<li>A content script or other extension
<a href="messaging.html">sends a message.</a>
<li>Another view in the extension (for example, a popup) calls
<code><a href="runtime.html#method-getBackgroundPage">chrome.runtime.getBackgroundPage()</a></code>.
</ul>

<p>
Once it has been loaded, the event page will stay running
as long as it is active (for example, calling an extension
API or issuing a network request). Additionally, the
event page will not unload until all visible views (for example,
popup windows) are closed.
</p>

<p>
Once the event page has been idle a short time
(a few seconds), the
<code><a href="runtime.html#event-onSuspend">chrome.runtime.onSuspend</a></code>
event is dispatched. The event page has a few more seconds to handle this
event before it is forcibly unloaded. Note that once the event is dispatched,
new activity will not keep the event page open.
</p>