forked from ChromeDevTools/debugger-protocol-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
606 lines (523 loc) · 31.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chrome DevTools Protocol Viewer</title>
<base href="/" />
<meta name="theme-color" content="#303F9F">
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>
<script src="bower_components/web-animations-js/web-animations-next.min.js"></script>
<link rel="import" href="index-imports.html" />
<link href="styles/protocol.css" rel="stylesheet">
<!-- Start Single Page Apps for GitHub Pages -->
<script>
// Single Page Apps for GitHub Pages
// https://github.com/rafrex/spa-github-pages
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
// ----------------------------------------------------------------------
// This script checks to see if a redirect is present in the query string
// and converts it back into the correct url and adds it to the
// browser's history using window.history.replaceState(...),
// which won't cause the browser to attempt to load the new url.
// When the single page app is loaded further down in this file,
// the correct url will be waiting in the browser's history for
// the single page app to route accordingly.
(function(l) {
if (l.search) {
var q = {};
l.search.slice(1).split('&').forEach(function(v) {
var a = v.split('=');
q[a[0]] = a.slice(1).join('=').replace(/~and~/g, '&');
});
if (q.p !== undefined) {
window.history.replaceState(null, null,
l.pathname.slice(0, -1) + (q.p || '') +
(q.q ? ('?' + q.q) : '') +
l.hash
);
}
}
}(window.location))
</script>
<!-- End Single Page Apps for GitHub Pages -->
</head>
<body unresolved>
<custom-style>
<style is="custom-style" include="custom-paper-material-styles">
[unresolved] > * {
display: none !important;
}
</style>
</custom-style>
<iron-location id="location"></iron-location>
<app-drawer-layout id="paperDrawerPanel">
<app-drawer slot="drawer" id="drawer">
<div id="drawerContainer">
<paper-dropdown-menu id="versions" label="Version">
<paper-listbox slot="dropdown-content" attr-for-selected="name">
<a href="1-2" name="1-2">
<paper-item>stable (1.2)</paper-item>
</a>
<a href="1-3" name="1-3">
<paper-item>stable RC (1.3)</paper-item>
</a>
<a href="tot" name="tot">
<paper-item>latest (tip-of-tree)</paper-item>
</a>
<a href="v8" name="v8">
<paper-item>v8-inspector (node)</paper-item>
</a>
<a href="" name="" class="homelink">
<paper-icon-button icon="home"></paper-icon-button><span>Home</span>
</a>
</paper-listbox>
</paper-dropdown-menu>
<div id="drawerToolbar" class="paper-font-title">Domains</div>
<iron-selector id="domainContainer" attr-for-selected="data-title">
<a data-title="Browser" class="tot 1-3">Browser</a>
<a data-title="Debugger" class="tot 1-2 1-3 v8">Debugger</a>
<a data-title="DOM" class="tot 1-2 1-3">DOM</a>
<a data-title="DOMDebugger" class="tot 1-2 1-3">DOMDebugger</a>
<a data-title="Emulation" class="tot 1-2 1-3">Emulation</a>
<a data-title="Input" class="tot 1-2 1-3">Input</a>
<a data-title="IO" class="tot 1-3">IO</a>
<a data-title="Log" class="tot 1-3">Log</a>
<a data-title="Network" class="tot 1-2 1-3">Network</a>
<a data-title="Page" class="tot 1-2 1-3">Page</a>
<a data-title="Performance" class="tot 1-3">Performance</a>
<a data-title="Profiler" class="tot 1-2 1-3 v8">Profiler</a>
<a data-title="Runtime" class="tot 1-2 1-3 v8">Runtime</a>
<a data-title="Security" class="tot 1-3">Security</a>
<a data-title="Target" class="tot 1-3">Target</a>
<a data-title="Console" class="tot deprecated v8">Console</a>
<a data-title="Schema" class="tot deprecated 1-2 v8">Schema</a>
<a data-title="Accessibility" class="tot experimental">Accessibility</a>
<a data-title="Animation" class="tot experimental">Animation</a>
<a data-title="ApplicationCache" class="tot experimental">ApplicationCache</a>
<a data-title="Audits" class="tot experimental">Audits</a>
<a data-title="BackgroundService" class="tot experimental">BackgroundService</a>
<a data-title="CacheStorage" class="tot experimental">CacheStorage</a>
<a data-title="Cast" class="tot experimental">Cast</a>
<a data-title="CSS" class="tot experimental">CSS</a>
<a data-title="Database" class="tot experimental">Database</a>
<a data-title="DeviceOrientation" class="tot experimental">DeviceOrientation</a>
<a data-title="DOMSnapshot" class="tot experimental">DOMSnapshot</a>
<a data-title="DOMStorage" class="tot experimental">DOMStorage</a>
<a data-title="Fetch" class="tot experimental">Fetch</a>
<a data-title="HeadlessExperimental" class="tot experimental">HeadlessExperimental</a>
<a data-title="HeapProfiler" class="tot experimental v8">HeapProfiler</a>
<a data-title="IndexedDB" class="tot experimental">IndexedDB</a>
<a data-title="Inspector" class="tot experimental">Inspector</a>
<a data-title="LayerTree" class="tot experimental">LayerTree</a>
<a data-title="Memory" class="tot experimental">Memory</a>
<a data-title="Overlay" class="tot experimental">Overlay</a>
<a data-title="ServiceWorker" class="tot experimental">ServiceWorker</a>
<a data-title="Storage" class="tot experimental">Storage</a>
<a data-title="SystemInfo" class="tot experimental">SystemInfo</a>
<a data-title="Tethering" class="tot experimental">Tethering</a>
<a data-title="Tracing" class="tot experimental">Tracing</a>
<a data-title="WebAudio" class="tot experimental">WebAudio</a>
<a data-title="WebAuthn" class="tot experimental">WebAuthn</a>
</iron-selector>
</div>
</app-drawer>
<div class="header-layout">
<app-toolbar id="mainToolbar">
<paper-icon-button id="paperToggle"
icon="menu" drawer-toggle aria-label="Open drawer menu"></paper-icon-button>
<div main-title class="top title">
Chrome DevTools Protocol Viewer
</div>
<cr-search-control id="searchButton"></cr-search-control>
</app-toolbar>
<main class="content">
<iron-pages id="main-selector" attr-for-selected="data-url" fallback-selection="404">
<section data-url="404">
Oops you hit a 404!
</section>
<cr-search-menu data-url="search" id="searchMenu"></cr-search-menu>
<section data-url="domain-summary" class="paper-material" elevation="1">
<a href="https://github.com/ChromeDevTools/debugger-protocol-viewer" class="gh-badge"><img
style=""
src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
alt="Fork me on GitHub"
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
<div id="domain-summary"></div>
</section>
<cr-domain data-url="domain"></cr-domain>
<section data-url="">
<div class="paper-material home-page-content" elevation="1">
<a href="https://github.com/ChromeDevTools/debugger-protocol-viewer" class="gh-badge"><img
style=""
src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
alt="Fork me on GitHub"
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
<p>The <b>Chrome DevTools Protocol</b> allows for tools to instrument, inspect, debug and profile Chromium, Chrome and other Blink-based browsers.
Many existing projects <a href="https://github.com/ChromeDevTools/awesome-chrome-devtools">currently use</a> the protocol.
The <a href="https://developers.google.com/web/tools/chrome-devtools/">Chrome DevTools</a> uses this protocol and the team maintains its API.
<p>Instrumentation is divided into a number of domains (DOM, Debugger, Network
etc.). Each domain defines a number of commands it supports and events it
generates. Both commands and events are serialized JSON objects of a fixed
structure.</p>
<h3>Protocol API Docs</h3>
<p>
<b><a href="tot/">The latest (tip-of-tree) protocol (tot)</a></b> —
It <a href="https://chromium.googlesource.com/chromium/src/+log/HEAD/third_party/blink/renderer/core/inspector/browser_protocol.pdl">changes frequently</a> and can break at any time. However it captures the full capabilities of the Protocol, whereas the stable release is a subset. There is no backwards compatibility support guaranteed for the capabilities it introduces.</p>
<p>
<b><a href="v8/">v8-inspector protocol (v8)</a></b> —
It is available in <a href="https://nodejs.org/en/blog/release/v6.3.0/">node 6.3+</a> and enables <a href="https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27">debugging & profiling</a> of Node.js apps.</p>
<p>
<b><a href="1-2/">stable 1.2 protocol (1-2)</a></b> —
The stable release of the protocol, tagged at Chrome 54. It includes a smaller subset of the complete protocol compatibilities.
<p>
<b><a href="1-3/">stable 1.3 protocol (1-3)</a></b> —
The stable release of the protocol, tagged at Chrome 64. It includes a smaller subset of the complete protocol compatibilities.
<h3>Resources</h3>
<p><a href="https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md">Getting Started with CDP</a></p>
<p>The <a href="https://github.com/chromedevtools/devtools-protocol">devtools-protocol repo</a> issue tracker can also be used for concerns with the protocol. It also hosts the canonical copy of the json files.
<p>Useful: <a href="https://developers.google.com/web/updates/2017/04/headless-chrome">Getting Started with Headless Chrome</a> and the <a href="https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md">Headless Chromium readme</a>.
<p>The <a href="https://github.com/cyrus-and/chrome-remote-interface/">chrome-remote-interface</a> node module is recommended, and its <a href="https://github.com/cyrus-and/chrome-remote-interface/wiki">wiki</a> and <a href="https://github.com/cyrus-and/chrome-remote-interface/issues?utf8=%E2%9C%93&q=is%3Aissue%20">issue tracker</a> are full of useful recipes.
<p>The <a href="https://github.com/ChromeDevTools/awesome-chrome-devtools#chrome-devtools-protocol">awesome-chrome-devtools</a> page links to many of the tools in the protocol ecosystem, including protocol API libraries in JavaScript, TypeScript, Python, Java, and Go.
<p>Consider subscribing to the <a href="https://groups.google.com/d/forum/chrome-debugging-protocol">chrome-debugging-protocol</a> mailing list.
<h3 id="remote">Basics: Using DevTools as protocol client</h3>
<p>The Developer Tools front-end can attach to a remotely running Chrome instance for debugging.
For this scenario to work, you should start your
<i>host</i> Chrome instance with the remote-debugging-port
command line switch:
</p>
<pre class="summary">chrome.exe --remote-debugging-port=9222</pre>
<p>Then you can start a separate <i>client</i> Chrome instance, using a distinct user profile:</p>
<pre class="summary">chrome.exe --user-data-dir=<some directory></pre>
<p>Now you can navigate to the given port from your <i>client</i> and attach to
any of the discovered tabs for debugging: <a href="http://localhost:9222">http://localhost:9222</a>
</p>
<p>You will find the Developer Tools interface identical to the embedded one and
here is why:
</p>
<ul>
<li>When you navigate your <i>client</i> browser to the remote's Chrome port,
Developer Tools front-end is being served from the <i>host</i> Chrome
as a Web Application from the Web Server.
</li>
<li>It fetches HTML, JavaScript and CSS files over HTTP
</li>
<li>Once loaded, Developer Tools establishes a Web Socket connection to its
host and starts exchanging JSON messages with it.
</li>
</ul>
<p>In this scenario, you can substitute Developer Tools front-end with your
own implementation. Instead of navigating to the HTML page at
http://localhost:9222, your application can discover available
pages by requesting: <a href="http://localhost:9222/json">http://localhost:9222/json</a> and getting a JSON object with information about inspectable pages along
with the WebSocket addresses that you could use in order to start
instrumenting them. See the <a href="#endpoints">HTTP Endpoints</a> section below for more.
</p>
<h3>Listening to the protocol</h3>
<p>This is especially handy to understand how the DevTools frontend makes use of the protocol. You can view all requests/responses and methods as they happen.</p>
<figure class="screenshot">
<a href="images/protocol-monitor.png" target="_blank" style="text-align: center; display:block;">
<img src="images/protocol-monitor.png" height="260" alt="Screenshot of the Protocol Monitor">
</a>
</figure>
<p>To use, first <a href="https://stackoverflow.com/a/15680012/89484">enable DevTools experiments</a>. Then click the ⋮ menu icon in the top-right of the DevTools, and select <i>Settings</i>. Select <i>Experiments</i> on the left of settings. Turn on "Protocol Monitor", then close and reopen DevTools. Now click the ⋮ menu icon again, choose <i>More Tools</i> and then select <i>Protocol monitor</i>.</p>
</p>
<p>You can also issue your own commands. First, <a href="https://stackoverflow.com/a/12291163/89484">open devtools-on-devtools</a>, then within the inner DevTools window, use <code>Main.sendOverProtocol()</code> in the console:</p>
<pre>
await Main.sendOverProtocol('Emulation.setDeviceMetricsOverride', {
mobile: true,
width: 412,
height: 732,
deviceScaleFactor: 2.625,
});
const data = await Main.sendOverProtocol("Page.captureScreenshot");</pre>
<h3 id="extension">DevTools protocol via Chrome extension</h3>
<p>
To allow chrome extensions to interact with the protocol, we introduced
<a href="https://developer.chrome.com/extensions/debugger.html">chrome.debugger</a>
extension API that exposes this JSON message
transport interface. As a result, you can not only attach to the remotely
running Chrome instance, but also instrument it from its own extension.
</p>
<p>Chrome Debugger Extension API provides a higher level API where command
domain, name and body are provided explicitly in the <code>sendCommand</code>
call. This API hides request ids and handles binding of the request with its
response, hence allowing <code>sendCommand</code> to report result in the
callback function call. One can also use this API in combination with the other
Extension APIs.
</p>
<p>If you are developing a Web-based IDE, you should implement an extension that
exposes debugging capabilities to your page and your IDE will be able to open
pages with the target application, set breakpoints there, evaluate expressions
in console, live edit JavaScript and CSS, display live DOM, network interaction
and any other aspect that Developer Tools is instrumenting today.
</p>
<p>Opening embedded Developer Tools will <a href="#simultaneous">terminate</a> the
remote connection and thus detach the extension.
</p>
<h3 id="faq">Frequently Asked Questions</h3>
<h4 id="how-is-the-protocol-defined">How is the protocol defined?</h4>
<p>The canonical protocol definitions live in the Chromium source tree: (<a href="https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/inspector/browser_protocol.pdl">browser_protocol.pdl</a> and <a href="https://cs.chromium.org/chromium/src/v8/include/js_protocol.pdl">js_protocol.pdl</a>). They are maintained manually by the DevTools engineering team. The declarative protocol definitions are used across tools; for instance, a binding layer is created within Chromium for the Chrome DevTools to interact with, and separately bindings generated for <a href="https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md#client_devtools-api">Chrome Headless’s C++ interface</a>.
<h4 id="json">Can I get the protocol as JSON?</h4>
<p>These canonical .pdl files are mirrored on GitHub <a href="https://github.com/ChromeDevTools/devtools-protocol/">in the devtools-protocol repo</a> where JSON versions, TypeScript definitions and closure typedefs are generated. Most tools rely on <a href="https://github.com/ChromeDevTools/devtools-protocol/tree/master/json">these JSON versions</a>.</p>
<p>Also, if you've set <code>--remote-debugging-port=9222</code> with Chrome, the complete protocol version it speaks is available at <code>localhost:9222/json/protocol</code>.</p>
<h4 id="how-do-i-access-the-browser-target">How do I access the browser target?</h4>
<p>The endpoint is exposed as <code>webSocketDebuggerUrl</code> in <code>/json/version</code>. Note the <code>browser</code> in the URL, rather than <code>page</code>. If Chrome was launched with <code>--remote-debugging-port=0</code> and chose an open port, the browser endpoint is written to both stderr and the <code>DevToolsActivePort</code> file in browser profile folder.</p>
<h4 id="simultaneous">Does the protocol support multiple simultaneous clients?</h4>
<p>
Chrome 63 introduced support for multiple clients. See <a href="https://developers.google.com/web/updates/2017/10/devtools-release-notes#multi-client">this article</a> for details.
</p>
<p>
Upon disconnnection, the outgoing client will receive a <code>detached</code> event.
For example: <code>{"method":"Inspector.detached","params":{"reason":"replaced_with_devtools"}}</code>.
View the <a href="https://code.google.com/p/chromium/codesearch#chromium/src/out/Debug/gen/chrome/common/extensions/api/debugger.cc&q=file:debugger.cc%20Reason%20ParseReason&sq=package:chromium&type=cs&">enum of
possible reasons.</a>
(For reference: the <a href="https://chromiumcodereview.appspot.com/11361034/">original patch</a>).
After disconnection, some apps have chosen to pause their state and offer a reconnect button.
</p>
<h3 id="endpoints">HTTP Endpoints</h3>
<p>If started with a remote-debugging-port, these HTTP endpoints are available on the same port. (<a href="https://cs.chromium.org/search/?q=f:devtools_http_handler.cc+%22command+%3D%3D+%22&sq=package:chromium&type=cs">Chromium implementation</a>)</p>
<h4 id="get-jsonversion">GET <code>/json/version</code></h4>
<p>Browser version metadata</p>
<pre class="sourceCode js">
{
"Browser": "Chrome/72.0.3601.0",
"Protocol-Version": "1.3",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3601.0 Safari/537.36",
"V8-Version": "7.2.233",
"WebKit-Version": "537.36 (@cfede9db1d154de0468cb0538479f34c0755a0f4)",
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/browser/b0b8a4fb-bb17-4359-9533-a8d9f3908bd8"
}
</pre>
<h4 id="get-json-or-jsonlist">GET <code>/json</code> or <code>/json/list</code></h4>
<p>A list of all available websocket targets.</p>
<pre class="sourceCode js">
[ {
"description": "",
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/DAB7FB6187B554E10B0BD18821265734",
"id": "DAB7FB6187B554E10B0BD18821265734",
"title": "Yahoo",
"type": "page",
"url": "https://www.yahoo.com/",
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/DAB7FB6187B554E10B0BD18821265734"
} ]
</pre>
<h4 id="get-jsonprotocol">GET <code>/json/protocol/</code></h4>
<p>The current devtools protocol, as JSON:</p>
<pre class="sourceCode js">
{
"domains": [
{
"domain": "Accessibility",
"experimental": true,
"dependencies": [
"DOM"
],
"types": [
{
"id": "AXValueType",
"description": "Enum of possible property types.",
"type": "string",
"enum": [
"boolean",
"tristate",
// ...
</pre>
<h4 id="get-jsonnewurl">GET <code>/json/new?{url}</code></h4>
<p>Opens a new tab. Responds with the websocket target data for the new tab.</p>
<h4 id="get-jsonactivatetargetid">GET <code>/json/activate/{targetId}</code></h4>
<p>Brings a page into the foreground (activate a tab).</p>
<p>For valid targets, the response is 200: <code>"Target activated"</code>. If the target is invalid, the response is 404: <code>"No such target id: {targetId}"</code></p>
<h4 id="get-jsonclosetargetid">GET <code>/json/close/{targetId}</code></h4>
<p>Closes the target page identified by <code>targetId</code>.</p>
<p>For valid targets, the response is 200: <code>"Target is closing"</code>. If the target is invalid, the response is 404: <code>"No such target id: {targetId}"</code></p>
<h4 id="websocket-devtoolspagetargetid">WebSocket <code>/devtools/page/{targetId}</code></h4>
<p>The WebSocket endpoint for the protocol.</p>
<h4 id="get-devtoolsinspector.html">GET <code>/devtools/inspector.html</code></h4>
<p>A copy of the DevTools frontend that ship with Chrome.</p>
</div>
</section>
</iron-pages>
</main>
</div>
</app-drawer-layout>
<script>
(function() {
const searchButton = document.getElementById('searchButton');
const searchMenu = document.getElementById('searchMenu');
const toolbar = document.getElementById('mainToolbar');
const listbox = document.getElementById('versions').querySelector('paper-listbox');
const mainSelector = document.getElementById('main-selector');
const domainContainer = document.getElementById('domainContainer');
const crDomain = document.querySelector('cr-domain');
const domainSummary = document.getElementById('domain-summary');
const mainElement = document.querySelector('main');
/**
* Mapping from domain shortcut to its full name. Used for updating the title.
*/
const domainToNameMapping = {
'1-2': 'stable (1.2)',
'1-3': 'stable (1.3)',
'tot': 'latest (tip-of-tree)',
'v8': 'v8-inspector (node)',
}
const defaultTitle = 'Chrome DevTools Protocol Viewer';
/**
* Hide links based on the domain that we are showing. The classList of
* each link has the (multiple) domains it is documented for.
* @param {String} domain The domain that we have currently selected
*/
function updateDomainSelectorLinks(domain) {
for (const link of domainContainer.querySelectorAll('a')) {
if (link.classList.contains(domain)) {
link.style.display = 'flex';
link.href = `${domain}/${link.dataset.title}`;
} else {
link.style.display = 'none';
}
}
}
let domainSelectionPromise;
async function updateLocationBindings(newLocation) {
// 18 is length of "/devtools-protocol"
let newPage = newLocation.startsWith('/devtools-protocol') ? newLocation.substring(18) : newLocation;
// Cut off start slash if it exists
if (newPage.startsWith('/')) {
newPage = newPage.substring(1);
}
let index, newVersion = newPage;
if ((index = newVersion.indexOf('/')) !== -1) {
newVersion = newVersion.substring(0, index);
}
listbox.selected = newVersion;
if (!domainToNameMapping[newVersion]) {
document.title = defaultTitle;
mainSelector.selected = newVersion;
newVersion = 'tot';
} else if (index === -1 || !newVersion.substring(index)) {
document.title = `${defaultTitle} - ${domainToNameMapping[newVersion]}`;
// Show the summary page if no sub-category was selected
mainSelector.selected = 'domain-summary';
fetch(`_versions/${newVersion}.html`)
.then(result => result.text())
.then((content) => domainSummary.innerHTML = `<h2 class="heading">${domainToNameMapping[newVersion]}</h2>${content}`);
}
updateDomainSelectorLinks(newVersion);
searchButton.protocolSrc = `search_index/${newVersion}.json`;
if (index !== -1 && newPage.substring(index) !== '/') {
let newDomain = newPage.substring(index + 1);
if (newDomain.endsWith('/')) {
newDomain = newDomain.substring(0, newDomain.length - 1);
}
document.title = `${defaultTitle} - ${newDomain}`;
// If we are switching between domains, but do not select a sub-category
// scroll all the way to the top again.
if (!location.hash) {
mainElement.scrollTop = '0';
}
domainSelectionPromise = new Promise(async (resolve) => {
mainSelector.selected = 'domain';
const result = await fetch('_data/' + newVersion + '/protocol.json');
const versionData = await result.json();
// confirm we have the dom elements present in the nav
const hardcodedDomains = Array.from(domainContainer.children).map(e => e.dataset.title);
versionData.domains.forEach(d => {
if (!hardcodedDomains.includes(d.domain)) console.error(`${d.domain} not present in domainContainer`);
});
crDomain.domain = versionData.domains.find(d => d.domain === newDomain);
domainContainer.selected = newDomain;
crDomain.version = newVersion;
// Wait for one frame and then resolve this promise, to make sure
// all data and elements are rendered, such that we can correctly
// scroll into view.
window.requestAnimationFrame(() => {
resolve();
domainSelectionPromise = undefined;
});
});
} else {
// We have not selected any domain, so we have to show the summar at the top
mainElement.scrollTop = '0';
}
}
const domainElement = document.querySelector('cr-domain');
function processHashUpdate() {
function scrollIntoView() {
let scrollTarget = null;
for (const details of domainElement.shadowRoot.querySelectorAll('cr-domain-details')) {
if (scrollTarget) continue;
if (`${details.type}-${details.name}` === location.hash) {
scrollTarget = details;
}
}
// Intra page link to a regular ID
if (!scrollTarget) {
scrollTarget = document.querySelector(`main [id="${location.hash}"]`);
}
if (scrollTarget) {
scrollTarget.scrollIntoView({behavior: 'instant', block: 'start'});
} else {
// After the hash update, we have not found any match.
// Could be the case that the hash is empty,
// or there is simply no match. Anyways, scroll all the way to the top
mainElement.scrollTop = '0';
}
}
window.requestAnimationFrame(() => {
// If we are still switching domains and fetching data (which is async)
// have to wait for that promise to resolve. Only then we have rendered
// data and can scroll to the correct element in the view
if (domainSelectionPromise) {
domainSelectionPromise.then(scrollIntoView);
} else {
scrollIntoView();
}
});
}
searchButton.resultsMenu = searchMenu;
let lastSelected;
searchButton.addEventListener('active', () => {
lastSelected = mainSelector.selected;
mainSelector.selected = 'search';
});
searchButton.addEventListener('inactive', () => {
mainSelector.selected = lastSelected;
});
searchMenu.addEventListener('item-activate', () => {
searchButton.handleItemActivate_();
});
const location = document.getElementById('location');
location.addEventListener('path-changed', (e) => {
searchButton.inputActive = false;
updateLocationBindings(e.detail.value);
});
location.addEventListener('hash-changed', (e) => {
processHashUpdate();
});
window.addEventListener('load', function() {
customElements.whenDefined('iron-location').then(() => {
updateLocationBindings(location.path);
processHashUpdate();
});
searchButton.addEventListener('active', function() {
toolbar.classList.add('search-active');
}, false);
searchButton.addEventListener('inactive', function() {
toolbar.classList.remove('search-active');
}, false);
});
if ('serviceWorker' in window.navigator) {
navigator.serviceWorker.register('service-worker.js');
}
})();
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-60854461-3', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>