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

Side by Side Diff: chrome/common/extensions/docs/server2/templates/intros/devtools_inspectedWindow.html

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

Powered by Google App Engine
This is Rietveld 408576698