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

Side by Side Diff: chrome/common/extensions/docs/server2/templates/articles/devtools_inspected_window.html

Issue 10832042: Extensions Docs Server: Doc conversion script (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment in converter.py Created 8 years, 4 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <h1 class="page_title">Devtools Inspected Window</h1><div id="pageData-name" cla ss="pageData"
2 >chrome.devtools.inspectedWindow.* APIs</div>
3
4 <p>
5 Use <code>chrome.devtools.inspectedWindow</code>
6 to interact with the inspected window:
7 obtain the tab ID for the inspected page,
8 evaluate the code in the context of inspected window,
9 reload the page,
10 or obtain the list of resources within the page.
11 </p><p>
12 See <a href="devtools.html">DevTools APIs summary</a> for
13 general introduction to using Developer Tools APIs.
14 </p>
15
16 <h2>Overview</h2>
17 <p>
18 The <a href="#property-tabId"><code>tabId</code></a> property
19 provides the tab identifier that you can use with the
20 <a href="tabs.html"><code>chrome.tabs.*</code></a> API calls.
21 However, please note that <code>chrome.tabs.*</code> API is not
22 exposed to the Developer Tools extension pages due to security considerations
23 &mdash; you will need to pass the tab ID to the background page and invoke
24 the <code>chrome.tabs.*</code> API functions from there.
25 </p>
26 <p>
27 The <code>eval()</code> method provides the ability for extensions to execute
28 JavaScript code in the context of the main frame of the inspected page.
29 This method is powerful when used in the right context
30 and dangerous when used inappropriately.
31 Use the <code>chrome.tabs.executeScript()</code> method
32 unless you need the specific functionality
33 that the <code>eval()</code> method provides.
34 </p>
35 <p>Here are the main differences between the
36 <code>eval()</code> and <code>chrome.tabs.executeScript()</code> methods:
37 </p><ul>
38 <li>The <code>eval()</code> method does not
39 use an isolated world for the code being evaluated, so the JavaScript state
40 of the inspected window is accessible to the code.
41 Use this method when access to the JavaScript state of the inspected page
42 is required.
43 </li><li>
44 The execution context of the code being evaluated includes the
45 <a href="http://code.google.com/chrome/devtools/docs/console.html">Developer
46 Tools console API</a>.
47 For example,
48 the code can use <code>inspect()</code> and <code>$0</code>.
49 </li><li>
50 The evaluated code may return a value that is passed to the extension callback.
51 The returned value has to be a valid JSON object (it may contain only
52 primitive JavaScript types and acyclic references to other JSON
53 objects).
54
55 <em>Please observe extra care while processing the data received from the
56 inspected page &mdash; the execution context is essentially controlled by the
57 inspected page; a malicious page may affect the data being returned to the
58 extension.</em>
59 </li></ul>
60 <p class="caution">
61 <strong>Important:</strong>
62 Due to the security considerations explained above, the
63 <a href="tabs.html#method-executeScript"><code
64 >chrome.tabs.executeScript()</code></a> method is the preferred way for an
65 extension to access DOM data of the inspected page in cases where the access to
66 JavaScript state of the inspected page is not required.</em>
67 </p><p>
68 The <code>reload()</code> method may be used to reload the inspected page.
69 Additionally, the caller can specify an override for the user agent string,
70 a script that will be injected early upon page load, and an option to force
71 reload of cached resources.
72 </p><p>
73 Use the <code>getResources()</code> call and the <code>onResourceContent</code>
74 event to obtain the list of resources (documents, stylesheets, scripts, images
75 etc) within the inspected page. The <code>getContent()</code> and <code
76 >setContent()</code> methods of the <code>Resource</code> class along with the
77 <code>onResourceContentCommitted</code> event may be used to support
78 modification of the resource content, for example, by an external editor.
79 </p>
80
81 <h2 id="overview-examples">Examples</h2>
82 <p>The following code checks for the version of jQuery used by the inspected
83 page:
84
85 <pre>
86 chrome.devtools.inspectedWindow.eval(
87 "jQuery.fn.jquery",
88 function(result, isException) {
89 if (isException)
90 console.log("the page is not using jQuery");
91 else
92 console.log("The page is using jQuery v" + result);
93 }
94 );
95 </pre>
96
97 <p>
98 You can find more examples that use Developer Tools APIs in
99 <a href="samples.html#devtools">Samples</a>.
100 </p>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698