Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/common/extensions/docs/content_scripts.html

Issue 339064: Add new user script injection point: document_idle. (Closed)
Patch Set: smaller, cleaner, better Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html><!-- This page is a placeholder for generated extensions api doc. Note: 1 <!DOCTYPE html><!-- This page is a placeholder for generated extensions api doc. Note:
2 1) The <head> information in this page is significant, should be uniform 2 1) The <head> information in this page is significant, should be uniform
3 across api docs and should be edited only with knowledge of the 3 across api docs and should be edited only with knowledge of the
4 templating mechanism. 4 templating mechanism.
5 3) All <body>.innerHTML is genereated as an rendering step. If viewed in a 5 3) All <body>.innerHTML is genereated as an rendering step. If viewed in a
6 browser, it will be re-generated from the template, json schema and 6 browser, it will be re-generated from the template, json schema and
7 authored overview content. 7 authored overview content.
8 4) The <body>.innerHTML is also generated by an offline step so that this 8 4) The <body>.innerHTML is also generated by an offline step so that this
9 page may easily be indexed by search engines. 9 page may easily be indexed by search engines.
10 --><html xmlns="http://www.w3.org/1999/xhtml"><head> 10 --><html xmlns="http://www.w3.org/1999/xhtml"><head>
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 <td>Optional. The list of JavaScript files to be injected into matching page s. These are injected in the order they appear in this array.</td> 339 <td>Optional. The list of JavaScript files to be injected into matching page s. These are injected in the order they appear in this array.</td>
340 </tr> 340 </tr>
341 <tr> 341 <tr>
342 <td>css</td> 342 <td>css</td>
343 <td>array of strings</td> 343 <td>array of strings</td>
344 <td>Optional. The list of CSS files to be injected into matching pages. Thes e are injected in the order they appear in this array, before any DOM is constru cted or displayed for the page.</td> 344 <td>Optional. The list of CSS files to be injected into matching pages. Thes e are injected in the order they appear in this array, before any DOM is constru cted or displayed for the page.</td>
345 </tr> 345 </tr>
346 <tr> 346 <tr>
347 <td>run_at</td> 347 <td>run_at</td>
348 <td>string</td> 348 <td>string</td>
349 <td>Optional. Controls when the files in <code>js</code> are injected. Can b e <code>"document_start"</code> or <code>"document_end"</code>. Defaults to <cod e>"document_end"</code>. In the case of <code>"document_start"</code>, the files are injected after any files from <code>"css"</code>, but before any other DOM is constructed or any other script is run. In the case of <code>"document_end"</ code>, the files are injected after the DOM is complete, but before subresources like images and frames have necessarily loaded.</td> 349 <td>Optional. Controls when the files in <code>js</code> are injected. Can b e <code>"document_start"</code>, <code>"document_end"</code>, or <code>"document _idle"</code>. Defaults to <code>"document_idle"</code>.
350
351 <br><br>
352
353 In the case of <code>"document_start"</code>, the files are injected after a ny files from <code>"css"</code>, but before any other DOM is constructed or any other script is run.
354
355 <br><br>
356
357 In the case of <code>"document_end"</code>, the files are injected immediate ly after the DOM is complete, but before subresources like images and frames hav e loaded.
358
359 <br><br>
360
361 In the case of <code>"document_idle"</code>, the browser chooses a time to i nject scripts between <code>"document_end"</code> and immediately after the <cod e><a href="http://www.whatwg.org/specs/web-apps/current-work/#handler-onload">wi ndow.onload</a></code> event fires. The exact moment of injection depends on how complex the document is and how long it is taking to load, and is optimized for page load speed.
362
363 <br><br>
364
365 <b>NOTE:</b> In <code>document_idle</code>, content scripts may not necessar ily receive the window.onload event, because they may run after it has
366 already fired. In most cases, listening for the onload event is unnecessary for content scripts running at <code>document_idle</code> because they are guara nteed to run after the DOM is complete. If your script definitely needs to run a fter <code>window.onload</code> you can check if it has already fired by using t he <code><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-documen t-readystate">document.readyState</a></code> property.</td>
350 </tr> 367 </tr>
351 </tbody></table> 368 </tbody></table>
352 369
353 370
354 <h2 id="execution-environment">Execution environment</h2> 371 <h2 id="execution-environment">Execution environment</h2>
355 372
356 <p>Content scripts execute in a special environment called an <em>isolated world </em>. They have access to the DOM of the page they are injected into, but not t o any JavaScript variables or functions created by the page. It looks to each co ntent script as if there is no other JavaScript executing on the page it is runn ing on. The same is true in reverse: JavaScript running on the page cannot call any functions or access any variables defined by content scripts. 373 <p>Content scripts execute in a special environment called an <em>isolated world </em>. They have access to the DOM of the page they are injected into, but not t o any JavaScript variables or functions created by the page. It looks to each co ntent script as if there is no other JavaScript executing on the page it is runn ing on. The same is true in reverse: JavaScript running on the page cannot call any functions or access any variables defined by content scripts.
357 374
358 </p><p>For example, consider this simple page: 375 </p><p>For example, consider this simple page:
359 376
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 urchinTracker(); 684 urchinTracker();
668 } 685 }
669 catch(e) {/* urchinTracker not available. */} 686 catch(e) {/* urchinTracker not available. */}
670 </script> 687 </script>
671 <!-- end analytics --> 688 <!-- end analytics -->
672 689
673 </div> <!-- /pageFooter --> 690 </div> <!-- /pageFooter -->
674 </div> <!-- /container --> 691 </div> <!-- /container -->
675 </body></html> 692 </body></html>
676 693
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698