OLD | NEW |
1 <!-- BEGIN AUTHORED CONTENT --> | 1 |
| 2 |
| 3 |
2 <p id="classSummary"> | 4 <p id="classSummary"> |
3 Use the <code>chrome.webNavigation</code> module to receive | 5 Use the <code>chrome.webNavigation</code> module to receive |
4 notifications about the status of navigations requests in-flight. | 6 notifications about the status of navigations requests in-flight. |
5 </p> | 7 </p> |
| 8 |
6 <h2>Manifest</h2> | 9 <h2>Manifest</h2> |
7 <p> | 10 <p> |
8 All <code>chrome.webNavigation</code> methods and events require you to declare | 11 All <code>chrome.webNavigation</code> methods and events require you to declare |
9 the "webNavigation" permission in the <a href="manifest.html">extension | 12 the "webNavigation" permission in the <a href="manifest.html">extension |
10 manifest</a>. | 13 manifest</a>. |
11 For example: | 14 For example: |
12 </p> | 15 </p> |
| 16 |
13 <pre>{ | 17 <pre>{ |
14 "name": "My extension", | 18 "name": "My extension", |
15 ... | 19 ... |
16 <b>"permissions": [ | 20 <b>"permissions": [ |
17 "webNavigation" | 21 "webNavigation" |
18 ]</b>, | 22 ]</b>, |
19 ... | 23 ... |
20 }</pre> | 24 }</pre> |
| 25 |
| 26 |
21 <h2>Examples</h2> | 27 <h2>Examples</h2> |
| 28 |
22 <p> | 29 <p> |
23 You can find simple examples of using the tabs module in the | 30 You can find simple examples of using the tabs module in the |
24 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension
s/docs/examples/api/webNavigation/">examples/api/webNavigation</a> | 31 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension
s/docs/examples/api/webNavigation/">examples/api/webNavigation</a> |
25 directory. | 32 directory. |
26 For other examples and for help in viewing the source code, see | 33 For other examples and for help in viewing the source code, see |
27 <a href="samples.html">Samples</a>. | 34 <a href="samples.html">Samples</a>. |
28 </p> | 35 </p> |
| 36 |
29 <h2>Event order</h2> | 37 <h2>Event order</h2> |
30 <p> | 38 <p> |
31 For a navigation that is successfully completed, events are fired in the | 39 For a navigation that is successfully completed, events are fired in the |
32 following order: | 40 following order: |
33 <pre> | 41 <pre> |
34 onBeforeNavigate -> onCommitted -> onDOMContentLoaded -> onCompleted | 42 onBeforeNavigate -> onCommitted -> onDOMContentLoaded -> onCompleted |
35 </pre> | 43 </pre> |
36 </p> | 44 </p> |
37 <p> | 45 <p> |
38 Any error that occurs during the process results in an | 46 Any error that occurs during the process results in an |
39 <code>onErrorOccurred</code> event. For a specific navigation, there are no | 47 <code>onErrorOccurred</code> event. For a specific navigation, there are no |
40 further events fired after <code>onErrorOccurred</code>. | 48 further events fired after <code>onErrorOccurred</code>. |
41 </p> | 49 </p> |
42 <p> | 50 <p> |
43 If a navigating frame contains subframes, its <code>onCommitted</code> is fired | 51 If a navigating frame contains subframes, its <code>onCommitted</code> is fired |
44 before any of its children's <code>onBeforeNavigate</code>; while | 52 before any of its children's <code>onBeforeNavigate</code>; while |
45 <code>onCompleted</code> is fired after all of its children's | 53 <code>onCompleted</code> is fired after all of its children's |
46 <code>onCompleted</code>. | 54 <code>onCompleted</code>. |
47 </p> | 55 </p> |
48 <p> | 56 <p> |
49 If the reference fragment of a frame is changed, a | 57 If the reference fragment of a frame is changed, a |
50 <code>onReferenceFragmentUpdated</code> event is fired. This event can fire any | 58 <code>onReferenceFragmentUpdated</code> event is fired. This event can fire any |
51 time after <code>onDOMContentLoaded</code>, even after | 59 time after <code>onDOMContentLoaded</code>, even after |
52 <code>onCompleted</code>. | 60 <code>onCompleted</code>. |
53 </p> | 61 </p> |
| 62 <p> |
| 63 If the history API is used to modify the state of a frame (e.g. using |
| 64 <code>history.pushState()</code>, a <code>onHistoryStateUpdated</code> event is |
| 65 fired. This event can fire any time after <code>onDOMContentLoaded</code>. |
| 66 </p> |
| 67 <p> |
| 68 If a navigation was triggered via <a |
| 69 href="https://support.google.com/chrome/bin/answer.py?answer=177873">Chrome |
| 70 Instant</a> or <a |
| 71 href="https://support.google.com/chrome/bin/answer.py?answer=1385029">Instant |
| 72 Pages</a>, a completely loaded page is swapped into the current tab. In that |
| 73 case, an <code>onTabReplaced</code> event is fired. |
| 74 </p> |
| 75 |
54 <h2>Relation to webRequest events</h2> | 76 <h2>Relation to webRequest events</h2> |
55 <p> | 77 <p> |
56 There is no defined ordering between events of the <a | 78 There is no defined ordering between events of the <a |
57 href="webRequest.html">webRequest API</a> and the events of the | 79 href="webRequest.html">webRequest API</a> and the events of the |
58 webNavigation API. It is possible that webRequest events are still received for | 80 webNavigation API. It is possible that webRequest events are still received for |
59 frames that already started a new navigation, or that a navigation only | 81 frames that already started a new navigation, or that a navigation only |
60 proceeds after the network resources are already fully loaded. | 82 proceeds after the network resources are already fully loaded. |
61 </p> | 83 </p> |
62 <p> | 84 <p> |
63 In general, the webNavigation events are closely related to the navigation | 85 In general, the webNavigation events are closely related to the navigation |
64 state that is displayed in the UI, while the webRequest events correspond to | 86 state that is displayed in the UI, while the webRequest events correspond to |
65 the state of the network stack which is generally opaque to the user. | 87 the state of the network stack which is generally opaque to the user. |
66 </p> | 88 </p> |
| 89 |
| 90 <h2>A note about tab IDs</h2> |
| 91 <p> |
| 92 Not all navigating tabs correspond to actual tabs in Chrome's UI, e.g., a tab |
| 93 that is being pre-rendered. Such tabs are not accessible via the |
| 94 <a href="tabs.html">tabs API</a> nor can you request information about them via |
| 95 <code>webNavigation.getFrame</code> or <code>webNavigation.getAllFrames</code>. |
| 96 Once such a tab is swapped in, an <code>onTabReplaced</code> event is fired and |
| 97 they become accessible via these APIs. |
| 98 </p> |
| 99 |
67 <h2>A note about timestamps</h2> | 100 <h2>A note about timestamps</h2> |
68 <p> | 101 <p> |
69 It's important to note that some technical oddities in the OS's handling | 102 It's important to note that some technical oddities in the OS's handling |
70 of distinct Chrome processes can cause the clock to be skewed between the | 103 of distinct Chrome processes can cause the clock to be skewed between the |
71 browser itself and extension processes. That means that WebNavigation's events' | 104 browser itself and extension processes. That means that WebNavigation's events' |
72 <code>timeStamp</code> property is only guaranteed to be <i>internally</i> | 105 <code>timeStamp</code> property is only guaranteed to be <i>internally</i> |
73 consistent. Comparing one event to another event will give you the correct | 106 consistent. Comparing one event to another event will give you the correct |
74 offset between them, but comparing them to the current time inside the | 107 offset between them, but comparing them to the current time inside the |
75 extension (via <code>(new Date()).getTime()</code>, for instance) might give | 108 extension (via <code>(new Date()).getTime()</code>, for instance) might give |
76 unexpected results. | 109 unexpected results. |
77 </p> | 110 </p> |
| 111 |
| 112 <h2>A note about frame and process IDs</h2> |
| 113 <p> |
| 114 Due to the multi-process nature of Chrome, a tab might use different processes |
| 115 to render the source and destination of a web page. Therefore, if a navigation |
| 116 takes place in a new process, you might receive events both from the new and |
| 117 the old page until the new navigation is committed (i.e. the |
| 118 <code>onCommitted</code> event is send for the new main frame). Because frame |
| 119 IDs are only unique for a given process, the webNavigation events include a |
| 120 process ID, so you can still determine which frame a navigation came from. |
| 121 </p> |
| 122 <p> |
| 123 Also note that during a provisional load the process might be switched several |
| 124 times. This happens when the load is redirected to a different site. In this |
| 125 case, you will receive repeated <code>onBeforeNavigate</code> and |
| 126 <code>onErrorOccurred</code> events, until you receive the final |
| 127 <code>onCommitted</code> event. |
| 128 </p> |
| 129 |
78 <h2>Transition types and qualifiers</h2> | 130 <h2>Transition types and qualifiers</h2> |
79 <p> | 131 <p> |
80 The webNavigation API's <code>onCommitted</code> event has a | 132 The webNavigation API's <code>onCommitted</code> event has a |
81 <code>transitionType</code> and a <code>transitionQualifiers</code> property. | 133 <code>transitionType</code> and a <code>transitionQualifiers</code> property. |
82 The <em>transition type</em> is the same as used in the <a | 134 The <em>transition type</em> is the same as used in the <a |
83 href="history.html#transition_types">history API</a> describing how the browser | 135 href="history.html#transition_types">history API</a> describing how the browser |
84 navigated to this particular URL. In addition, several <em>transition | 136 navigated to this particular URL. In addition, several <em>transition |
85 qualifiers</em> can be returned that further define the navigation. | 137 qualifiers</em> can be returned that further define the navigation. |
86 </p> | 138 </p> |
87 <p> | 139 <p> |
(...skipping 23 matching lines...) Expand all Loading... |
111 The user used the Forward or Back button to initiate the navigation. | 163 The user used the Forward or Back button to initiate the navigation. |
112 </td> | 164 </td> |
113 </tr> | 165 </tr> |
114 <tr> | 166 <tr> |
115 <td>"from_address_bar"</td> | 167 <td>"from_address_bar"</td> |
116 <td> | 168 <td> |
117 The user initiated the navigation from the address bar (aka Omnibox). | 169 The user initiated the navigation from the address bar (aka Omnibox). |
118 </td> | 170 </td> |
119 </tr> | 171 </tr> |
120 </table> | 172 </table> |
121 <!-- END AUTHORED CONTENT --> | 173 |
| 174 |
OLD | NEW |