OLD | NEW |
1 <h1>Background Pages</h1> | 1 <h1>Background Pages</h1> |
2 | 2 |
3 | 3 |
4 <p id="eventPageWarning" class="warning"> | 4 <p id="eventPageWarning" class="warning"> |
5 <em>Caution:</em> Consider using event pages instead. | 5 <em>Caution:</em> Consider using event pages instead. |
6 <a href="event_pages.html">Learn more</a>. | 6 <a href="event_pages">Learn more</a>. |
7 </p> | 7 </p> |
8 | 8 |
9 <p> | 9 <p> |
10 A common need for extensions is to have | 10 A common need for extensions is to have |
11 a single long-running script to manage some task or state. | 11 a single long-running script to manage some task or state. |
12 Background pages to the rescue. | 12 Background pages to the rescue. |
13 </p> | 13 </p> |
14 | 14 |
15 <p> | 15 <p> |
16 As the <a href="overview.html#arch">architecture overview</a> explains, | 16 As the <a href="overview#arch">architecture overview</a> explains, |
17 the background page is an HTML page that runs in the extension process. | 17 the background page is an HTML page that runs in the extension process. |
18 It exists for the lifetime of your extension, | 18 It exists for the lifetime of your extension, |
19 and only one instance of it at a time is active. (Exception: if your | 19 and only one instance of it at a time is active. (Exception: if your |
20 extension uses <a href="manifest/incognito.html">incognito</a> | 20 extension uses <a href="manifest/incognito">incognito</a> |
21 "split" mode, a second instance is created for incognito windows.) | 21 "split" mode, a second instance is created for incognito windows.) |
22 </p> | 22 </p> |
23 | 23 |
24 <p> | 24 <p> |
25 In a typical extension with a background page, | 25 In a typical extension with a background page, |
26 the UI — | 26 the UI — |
27 for example, the browser action or page action | 27 for example, the browser action or page action |
28 and any options page — | 28 and any options page — |
29 is implemented by dumb views. | 29 is implemented by dumb views. |
30 When the view needs some state, | 30 When the view needs some state, |
31 it requests the state from the background page. | 31 it requests the state from the background page. |
32 When the background page notices a state change, | 32 When the background page notices a state change, |
33 the background page tells the views to update. | 33 the background page tells the views to update. |
34 </p> | 34 </p> |
35 | 35 |
36 <h2 id="manifest">Manifest</h2> | 36 <h2 id="manifest">Manifest</h2> |
37 | 37 |
38 <p> | 38 <p> |
39 Register your background page in the | 39 Register your background page in the |
40 <a href="manifest.html">extension manifest</a>. | 40 <a href="manifest">extension manifest</a>. |
41 In the common case, a background page | 41 In the common case, a background page |
42 does not require any HTML markup. | 42 does not require any HTML markup. |
43 These kind of background pages can be | 43 These kind of background pages can be |
44 implemented using JavaScript files alone, | 44 implemented using JavaScript files alone, |
45 like this: | 45 like this: |
46 </p> | 46 </p> |
47 | 47 |
48 <pre data-filename="manifest.json"> | 48 <pre data-filename="manifest.json"> |
49 { | 49 { |
50 "name": "My extension", | 50 "name": "My extension", |
(...skipping 25 matching lines...) Expand all Loading... |
76 <b>"background": { | 76 <b>"background": { |
77 "page": "background.html" | 77 "page": "background.html" |
78 }</b>, | 78 }</b>, |
79 ... | 79 ... |
80 }</pre> | 80 }</pre> |
81 | 81 |
82 <p> | 82 <p> |
83 If you need the browser to start up early—so | 83 If you need the browser to start up early—so |
84 you can display notifications, for example—then | 84 you can display notifications, for example—then |
85 you might also want to specify the | 85 you might also want to specify the |
86 <a href="declare_permissions.html#background">"background" permission</a>. | 86 <a href="declare_permissions#background">"background" permission</a>. |
87 </p> | 87 </p> |
88 | 88 |
89 | 89 |
90 <h2 id="details">Details</h2> | 90 <h2 id="details">Details</h2> |
91 | 91 |
92 <p> | 92 <p> |
93 You can communicate between your various pages using direct script calls, | 93 You can communicate between your various pages using direct script calls, |
94 similar to how frames can communicate. | 94 similar to how frames can communicate. |
95 The $(ref:extension.getViews) method | 95 The $(ref:extension.getViews) method |
96 returns a list of window objects | 96 returns a list of window objects |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 <body> | 154 <body> |
155 <p> | 155 <p> |
156 Image here: | 156 Image here: |
157 </p> | 157 </p> |
158 | 158 |
159 <img id="target" src="white.png" width="640" height="480"> | 159 <img id="target" src="white.png" width="640" height="480"> |
160 | 160 |
161 </body> | 161 </body> |
162 </html> | 162 </html> |
163 </pre> | 163 </pre> |
OLD | NEW |