dragonfly_chrome_headless 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dragonfly_chrome_headless.gemspec +27 -0
- data/lib/dragonfly_chrome_headless.rb +9 -0
- data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
- data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
- data/lib/dragonfly_chrome_headless/version.rb +3 -0
- data/node_modules/.bin/chrome-remote-interface +1 -0
- data/node_modules/.bin/mkdirp +1 -0
- data/node_modules/.bin/rimraf +1 -0
- data/node_modules/@types/core-js/LICENSE +21 -0
- data/node_modules/@types/core-js/README.md +16 -0
- data/node_modules/@types/core-js/index.d.ts +2452 -0
- data/node_modules/@types/core-js/package.json +85 -0
- data/node_modules/@types/mkdirp/README.md +18 -0
- data/node_modules/@types/mkdirp/index.d.ts +14 -0
- data/node_modules/@types/mkdirp/package.json +77 -0
- data/node_modules/@types/mkdirp/types-metadata.json +25 -0
- data/node_modules/@types/node/README.md +16 -0
- data/node_modules/@types/node/index.d.ts +4132 -0
- data/node_modules/@types/node/package.json +84 -0
- data/node_modules/balanced-match/.npmignore +5 -0
- data/node_modules/balanced-match/LICENSE.md +21 -0
- data/node_modules/balanced-match/README.md +91 -0
- data/node_modules/balanced-match/index.js +59 -0
- data/node_modules/balanced-match/package.json +112 -0
- data/node_modules/brace-expansion/README.md +123 -0
- data/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/brace-expansion/package.json +114 -0
- data/node_modules/chrome-launcher/.clang-format +6 -0
- data/node_modules/chrome-launcher/.npmignore +11 -0
- data/node_modules/chrome-launcher/README.md +123 -0
- data/node_modules/chrome-launcher/ask.js +32 -0
- data/node_modules/chrome-launcher/ask.ts +35 -0
- data/node_modules/chrome-launcher/chrome-finder.js +157 -0
- data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
- data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
- data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
- data/node_modules/chrome-launcher/compiled-check.js +14 -0
- data/node_modules/chrome-launcher/flags.js +27 -0
- data/node_modules/chrome-launcher/flags.ts +26 -0
- data/node_modules/chrome-launcher/index.js +7 -0
- data/node_modules/chrome-launcher/index.ts +1 -0
- data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
- data/node_modules/chrome-launcher/package.json +116 -0
- data/node_modules/chrome-launcher/random-port.js +24 -0
- data/node_modules/chrome-launcher/random-port.ts +23 -0
- data/node_modules/chrome-launcher/tsconfig.json +19 -0
- data/node_modules/chrome-launcher/utils.js +52 -0
- data/node_modules/chrome-launcher/utils.ts +44 -0
- data/node_modules/chrome-launcher/yarn.lock +1486 -0
- data/node_modules/chrome-remote-interface/LICENSE +18 -0
- data/node_modules/chrome-remote-interface/README.md +849 -0
- data/node_modules/chrome-remote-interface/bin/client.js +337 -0
- data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
- data/node_modules/chrome-remote-interface/index.js +39 -0
- data/node_modules/chrome-remote-interface/lib/api.js +84 -0
- data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
- data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
- data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
- data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
- data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
- data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
- data/node_modules/chrome-remote-interface/package.json +128 -0
- data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
- data/node_modules/commander/Readme.md +195 -0
- data/node_modules/commander/index.js +851 -0
- data/node_modules/commander/package.json +92 -0
- data/node_modules/concat-map/.travis.yml +4 -0
- data/node_modules/concat-map/LICENSE +18 -0
- data/node_modules/concat-map/README.markdown +62 -0
- data/node_modules/concat-map/example/map.js +6 -0
- data/node_modules/concat-map/index.js +13 -0
- data/node_modules/concat-map/package.json +117 -0
- data/node_modules/concat-map/test/map.js +39 -0
- data/node_modules/debug/.coveralls.yml +1 -0
- data/node_modules/debug/.eslintrc +11 -0
- data/node_modules/debug/.npmignore +9 -0
- data/node_modules/debug/.travis.yml +14 -0
- data/node_modules/debug/CHANGELOG.md +357 -0
- data/node_modules/debug/LICENSE +19 -0
- data/node_modules/debug/Makefile +50 -0
- data/node_modules/debug/Readme.md +312 -0
- data/node_modules/debug/component.json +19 -0
- data/node_modules/debug/karma.conf.js +70 -0
- data/node_modules/debug/node.js +1 -0
- data/node_modules/debug/package.json +124 -0
- data/node_modules/debug/src/browser.js +185 -0
- data/node_modules/debug/src/debug.js +202 -0
- data/node_modules/debug/src/index.js +10 -0
- data/node_modules/debug/src/node.js +246 -0
- data/node_modules/fs.realpath/LICENSE +43 -0
- data/node_modules/fs.realpath/README.md +33 -0
- data/node_modules/fs.realpath/index.js +66 -0
- data/node_modules/fs.realpath/old.js +303 -0
- data/node_modules/fs.realpath/package.json +94 -0
- data/node_modules/glob/LICENSE +15 -0
- data/node_modules/glob/README.md +368 -0
- data/node_modules/glob/changelog.md +67 -0
- data/node_modules/glob/common.js +240 -0
- data/node_modules/glob/glob.js +790 -0
- data/node_modules/glob/package.json +112 -0
- data/node_modules/glob/sync.js +486 -0
- data/node_modules/html-pdf-chrome/.npmignore +9 -0
- data/node_modules/html-pdf-chrome/LICENSE +21 -0
- data/node_modules/html-pdf-chrome/README.md +165 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
- data/node_modules/html-pdf-chrome/package.json +133 -0
- data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
- data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
- data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
- data/node_modules/html-pdf-chrome/src/index.ts +179 -0
- data/node_modules/inflight/LICENSE +15 -0
- data/node_modules/inflight/README.md +37 -0
- data/node_modules/inflight/inflight.js +54 -0
- data/node_modules/inflight/package.json +105 -0
- data/node_modules/inherits/LICENSE +16 -0
- data/node_modules/inherits/README.md +42 -0
- data/node_modules/inherits/inherits.js +7 -0
- data/node_modules/inherits/inherits_browser.js +23 -0
- data/node_modules/inherits/package.json +97 -0
- data/node_modules/lighthouse-logger/README.md +4 -0
- data/node_modules/lighthouse-logger/index.js +212 -0
- data/node_modules/lighthouse-logger/package.json +69 -0
- data/node_modules/lighthouse-logger/yarn.lock +13 -0
- data/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/minimatch/README.md +209 -0
- data/node_modules/minimatch/minimatch.js +923 -0
- data/node_modules/minimatch/package.json +99 -0
- data/node_modules/minimist/.travis.yml +4 -0
- data/node_modules/minimist/LICENSE +18 -0
- data/node_modules/minimist/example/parse.js +2 -0
- data/node_modules/minimist/index.js +187 -0
- data/node_modules/minimist/package.json +101 -0
- data/node_modules/minimist/readme.markdown +73 -0
- data/node_modules/minimist/test/dash.js +24 -0
- data/node_modules/minimist/test/default_bool.js +20 -0
- data/node_modules/minimist/test/dotted.js +16 -0
- data/node_modules/minimist/test/long.js +31 -0
- data/node_modules/minimist/test/parse.js +318 -0
- data/node_modules/minimist/test/parse_modified.js +9 -0
- data/node_modules/minimist/test/short.js +67 -0
- data/node_modules/minimist/test/whitespace.js +8 -0
- data/node_modules/mkdirp/.travis.yml +8 -0
- data/node_modules/mkdirp/LICENSE +21 -0
- data/node_modules/mkdirp/bin/cmd.js +33 -0
- data/node_modules/mkdirp/bin/usage.txt +12 -0
- data/node_modules/mkdirp/examples/pow.js +6 -0
- data/node_modules/mkdirp/index.js +98 -0
- data/node_modules/mkdirp/package.json +93 -0
- data/node_modules/mkdirp/readme.markdown +100 -0
- data/node_modules/mkdirp/test/chmod.js +41 -0
- data/node_modules/mkdirp/test/clobber.js +38 -0
- data/node_modules/mkdirp/test/mkdirp.js +28 -0
- data/node_modules/mkdirp/test/opts_fs.js +29 -0
- data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
- data/node_modules/mkdirp/test/perm.js +32 -0
- data/node_modules/mkdirp/test/perm_sync.js +36 -0
- data/node_modules/mkdirp/test/race.js +37 -0
- data/node_modules/mkdirp/test/rel.js +32 -0
- data/node_modules/mkdirp/test/return.js +25 -0
- data/node_modules/mkdirp/test/return_sync.js +24 -0
- data/node_modules/mkdirp/test/root.js +19 -0
- data/node_modules/mkdirp/test/sync.js +32 -0
- data/node_modules/mkdirp/test/umask.js +28 -0
- data/node_modules/mkdirp/test/umask_sync.js +32 -0
- data/node_modules/ms/README.md +51 -0
- data/node_modules/ms/index.js +152 -0
- data/node_modules/ms/license.md +21 -0
- data/node_modules/ms/package.json +109 -0
- data/node_modules/once/LICENSE +15 -0
- data/node_modules/once/README.md +79 -0
- data/node_modules/once/once.js +42 -0
- data/node_modules/once/package.json +101 -0
- data/node_modules/path-is-absolute/index.js +20 -0
- data/node_modules/path-is-absolute/license +21 -0
- data/node_modules/path-is-absolute/package.json +111 -0
- data/node_modules/path-is-absolute/readme.md +59 -0
- data/node_modules/rimraf/LICENSE +15 -0
- data/node_modules/rimraf/README.md +101 -0
- data/node_modules/rimraf/bin.js +50 -0
- data/node_modules/rimraf/package.json +99 -0
- data/node_modules/rimraf/rimraf.js +363 -0
- data/node_modules/ultron/LICENSE +22 -0
- data/node_modules/ultron/index.js +138 -0
- data/node_modules/ultron/package.json +112 -0
- data/node_modules/wrappy/LICENSE +15 -0
- data/node_modules/wrappy/README.md +36 -0
- data/node_modules/wrappy/package.json +97 -0
- data/node_modules/wrappy/wrappy.js +33 -0
- data/node_modules/ws/LICENSE +21 -0
- data/node_modules/ws/README.md +259 -0
- data/node_modules/ws/SECURITY.md +33 -0
- data/node_modules/ws/index.js +15 -0
- data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
- data/node_modules/ws/lib/BufferUtil.js +15 -0
- data/node_modules/ws/lib/ErrorCodes.js +28 -0
- data/node_modules/ws/lib/EventTarget.js +158 -0
- data/node_modules/ws/lib/Extensions.js +69 -0
- data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
- data/node_modules/ws/lib/Receiver.js +520 -0
- data/node_modules/ws/lib/Sender.js +438 -0
- data/node_modules/ws/lib/Validation.fallback.js +9 -0
- data/node_modules/ws/lib/Validation.js +17 -0
- data/node_modules/ws/lib/WebSocket.js +705 -0
- data/node_modules/ws/lib/WebSocketServer.js +336 -0
- data/node_modules/ws/package.json +122 -0
- data/package.json +26 -0
- data/samples/sample.html +13 -0
- data/script/rasterize.js +18 -0
- metadata +325 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2017 Andrea Cardaci <cyrus.and@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,849 @@
|
|
1
|
+
chrome-remote-interface [](https://travis-ci.org/cyrus-and/chrome-remote-interface)
|
2
|
+
=======================
|
3
|
+
|
4
|
+
[Chrome Debugging Protocol] interface that helps to instrument Chrome (or any
|
5
|
+
other suitable [implementation](#implementations)) by providing a simple
|
6
|
+
abstraction of commands and notifications using a straightforward JavaScript
|
7
|
+
API.
|
8
|
+
|
9
|
+
This module is one of the many [third-party protocol clients][3rd-party].
|
10
|
+
|
11
|
+
[3rd-party]: https://developer.chrome.com/devtools/docs/debugging-clients#chrome-remote-interface
|
12
|
+
|
13
|
+
Sample API usage
|
14
|
+
----------------
|
15
|
+
|
16
|
+
The following snippet loads `https://github.com` and dumps every request made:
|
17
|
+
|
18
|
+
```js
|
19
|
+
const CDP = require('chrome-remote-interface');
|
20
|
+
|
21
|
+
CDP((client) => {
|
22
|
+
// extract domains
|
23
|
+
const {Network, Page} = client;
|
24
|
+
// setup handlers
|
25
|
+
Network.requestWillBeSent((params) => {
|
26
|
+
console.log(params.request.url);
|
27
|
+
});
|
28
|
+
Page.loadEventFired(() => {
|
29
|
+
client.close();
|
30
|
+
});
|
31
|
+
// enable events then start!
|
32
|
+
Promise.all([
|
33
|
+
Network.enable(),
|
34
|
+
Page.enable()
|
35
|
+
]).then(() => {
|
36
|
+
return Page.navigate({url: 'https://github.com'});
|
37
|
+
}).catch((err) => {
|
38
|
+
console.error(err);
|
39
|
+
client.close();
|
40
|
+
});
|
41
|
+
}).on('error', (err) => {
|
42
|
+
// cannot connect to the remote endpoint
|
43
|
+
console.error(err);
|
44
|
+
});
|
45
|
+
```
|
46
|
+
|
47
|
+
Find more examples in the [wiki], in particular notice how the above can be
|
48
|
+
rewritten using the [`async`/`await`][async-await-example] primitives.
|
49
|
+
|
50
|
+
[wiki]: https://github.com/cyrus-and/chrome-remote-interface/wiki
|
51
|
+
[async-await-example]: https://github.com/cyrus-and/chrome-remote-interface/wiki/Async-await-example
|
52
|
+
|
53
|
+
Installation
|
54
|
+
------------
|
55
|
+
|
56
|
+
npm install chrome-remote-interface
|
57
|
+
|
58
|
+
Install globally (`-g`) to just use the [bundled client](#bundled-client).
|
59
|
+
|
60
|
+
Implementations
|
61
|
+
---------------
|
62
|
+
|
63
|
+
This module should work with every application implementing the
|
64
|
+
[Chrome Debugging Protocol]. In particular, it has been tested against the
|
65
|
+
following implementations:
|
66
|
+
|
67
|
+
Implementation | Protocol version | [Protocol] | [List] | [New] | [Activate] | [Close] | [Version]
|
68
|
+
---------------------------|--------------------|------------|--------|-------|------------|---------|-----------
|
69
|
+
[Google Chrome][1.1] | [tip-of-tree][1.2] | yes | yes | yes | yes | yes | yes
|
70
|
+
[Microsoft Edge][2.1] | [*partial*][2.2] | yes | yes | no | no | no | yes
|
71
|
+
[Node.js][3.1] ([v6.3.0]+) | [node][3.2] | yes | no | no | no | no | yes
|
72
|
+
[Safari (iOS)][4.1] | [*partial*][4.2] | no | yes | no | no | no | no
|
73
|
+
|
74
|
+
[1.1]: #chromechromium
|
75
|
+
[1.2]: https://chromedevtools.github.io/devtools-protocol/tot/
|
76
|
+
|
77
|
+
[2.1]: #edge
|
78
|
+
[2.2]: https://github.com/Microsoft/edge-diagnostics-adapter/wiki/Supported-features-and-API
|
79
|
+
|
80
|
+
[3.1]: #nodejs
|
81
|
+
[3.2]: https://chromedevtools.github.io/devtools-protocol/v8/
|
82
|
+
|
83
|
+
[4.1]: #safari-ios
|
84
|
+
[4.2]: http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/inspector/protocol
|
85
|
+
|
86
|
+
[v6.3.0]: https://nodejs.org/en/blog/release/v6.3.0/
|
87
|
+
|
88
|
+
[Protocol]: #cdpprotocoloptions-callback
|
89
|
+
[List]: #cdplistoptions-callback
|
90
|
+
[New]: #cdpnewoptions-callback
|
91
|
+
[Activate]: #cdpactivateoptions-callback
|
92
|
+
[Close]: #cdpcloseoptions-callback
|
93
|
+
[Version]: #cdpversionoptions-callback
|
94
|
+
|
95
|
+
The meaning of *target* varies according to the implementation, for example,
|
96
|
+
each Chrome tab represents a target whereas for Node.js a target is the
|
97
|
+
currently inspected script.
|
98
|
+
|
99
|
+
Setup
|
100
|
+
-----
|
101
|
+
|
102
|
+
An instance of either Chrome itself or another implementation needs to be
|
103
|
+
running on a known port in order to use this module (defaults to
|
104
|
+
`localhost:9222`).
|
105
|
+
|
106
|
+
### Chrome/Chromium
|
107
|
+
|
108
|
+
#### Desktop
|
109
|
+
|
110
|
+
Start Chrome with the `--remote-debugging-port` option, for example:
|
111
|
+
|
112
|
+
google-chrome --remote-debugging-port=9222
|
113
|
+
|
114
|
+
##### Headless
|
115
|
+
|
116
|
+
Since version 59, additionally use the `--headless` option, for example:
|
117
|
+
|
118
|
+
google-chrome --headless --remote-debugging-port=9222
|
119
|
+
|
120
|
+
#### Android
|
121
|
+
|
122
|
+
Plug the device and enable the [port forwarding][adb], for example:
|
123
|
+
|
124
|
+
adb forward tcp:9222 localabstract:chrome_devtools_remote
|
125
|
+
|
126
|
+
[adb]: https://developer.chrome.com/devtools/docs/remote-debugging-legacy
|
127
|
+
|
128
|
+
##### WebView
|
129
|
+
|
130
|
+
In order to be inspectable, a WebView must
|
131
|
+
be [configured for debugging][webview] and the corresponding process ID must be
|
132
|
+
known. There are several ways to obtain it, for example:
|
133
|
+
|
134
|
+
adb shell grep -a webview_devtools_remote /proc/net/unix
|
135
|
+
|
136
|
+
Finally, port forwarding can be enabled as follows:
|
137
|
+
|
138
|
+
adb forward tcp:9222 localabstract:webview_devtools_remote_<pid>
|
139
|
+
|
140
|
+
[webview]: https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews#configure_webviews_for_debugging
|
141
|
+
|
142
|
+
### Edge
|
143
|
+
|
144
|
+
Install and run the [Edge Diagnostics Adapter][edge-adapter].
|
145
|
+
|
146
|
+
[edge-adapter]: https://github.com/Microsoft/edge-diagnostics-adapter
|
147
|
+
|
148
|
+
### Node.js
|
149
|
+
|
150
|
+
Start Node.js with the `--inspect` option, for example:
|
151
|
+
|
152
|
+
node --inspect=9222 script.js
|
153
|
+
|
154
|
+
### Safari (iOS)
|
155
|
+
|
156
|
+
Install and run the [iOS WebKit Debug Proxy][iwdp].
|
157
|
+
|
158
|
+
[iwdp]: https://github.com/google/ios-webkit-debug-proxy
|
159
|
+
|
160
|
+
Bundled client
|
161
|
+
--------------
|
162
|
+
|
163
|
+
This module comes with a bundled client application that can be used to
|
164
|
+
interactively control a remote instance.
|
165
|
+
|
166
|
+
### Target management
|
167
|
+
|
168
|
+
The bundled client exposes subcommands to interact with the HTTP frontend
|
169
|
+
(e.g., [List](#cdplistoptions-callback), [New](#cdpnewoptions-callback), etc.),
|
170
|
+
run with `--help` to display the list of available options.
|
171
|
+
|
172
|
+
Here are some examples:
|
173
|
+
|
174
|
+
```javascript
|
175
|
+
$ chrome-remote-interface new 'http://example.com'
|
176
|
+
{
|
177
|
+
"description": "",
|
178
|
+
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/b049bb56-de7d-424c-a331-6ae44cf7ae01",
|
179
|
+
"id": "b049bb56-de7d-424c-a331-6ae44cf7ae01",
|
180
|
+
"thumbnailUrl": "/thumb/b049bb56-de7d-424c-a331-6ae44cf7ae01",
|
181
|
+
"title": "",
|
182
|
+
"type": "page",
|
183
|
+
"url": "http://example.com/",
|
184
|
+
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/b049bb56-de7d-424c-a331-6ae44cf7ae01"
|
185
|
+
}
|
186
|
+
$ chrome-remote-interface close 'b049bb56-de7d-424c-a331-6ae44cf7ae01'
|
187
|
+
```
|
188
|
+
|
189
|
+
### Inspection
|
190
|
+
|
191
|
+
Using the `inspect` subcommand it is possible to
|
192
|
+
perform [command execution](#clientdomainmethodparams-callback)
|
193
|
+
and [event binding](#clientdomaineventcallback) in a REPL fashion. But unlike
|
194
|
+
the regular API the callbacks are overridden to conveniently display the result
|
195
|
+
of the commands and the message of the events. Also, the event binding is
|
196
|
+
simplified here, executing a shorthand method (e.g., `Page.loadEventFired()`)
|
197
|
+
toggles the event registration.
|
198
|
+
|
199
|
+
Remember that the REPL interface provides completion.
|
200
|
+
|
201
|
+
Here is a sample session:
|
202
|
+
|
203
|
+
```javascript
|
204
|
+
$ chrome-remote-interface inspect
|
205
|
+
>>> Runtime.evaluate({expression: 'window.location.toString()'})
|
206
|
+
{ result:
|
207
|
+
{ result:
|
208
|
+
{ type: 'string',
|
209
|
+
value: 'https://www.google.it/_/chrome/newtab?espv=2&ie=UTF-8' },
|
210
|
+
wasThrown: false } }
|
211
|
+
>>> Page.enable()
|
212
|
+
{ result: {} }
|
213
|
+
>>> Page.loadEventFired() // registered
|
214
|
+
{ 'Page.loadEventFired': true }
|
215
|
+
>>> Page.loadEventFired() // unregistered
|
216
|
+
{ 'Page.loadEventFired': false }
|
217
|
+
>>> Page.loadEventFired() // registered
|
218
|
+
{ 'Page.loadEventFired': true }
|
219
|
+
>>> Page.navigate({url: 'https://github.com'})
|
220
|
+
{ result: { frameId: '28677.1' } }
|
221
|
+
{ 'Page.loadEventFired': { timestamp: 21385.383076 } }
|
222
|
+
>>> Runtime.evaluate({expression: 'window.location.toString()'})
|
223
|
+
{ result:
|
224
|
+
{ result: { type: 'string', value: 'https://github.com/' },
|
225
|
+
wasThrown: false } }
|
226
|
+
```
|
227
|
+
|
228
|
+
#### Event filtering
|
229
|
+
|
230
|
+
To reduce the amount of data displayed by the event listeners it is possible to
|
231
|
+
provide a filter function. In this example only the resource URL is shown:
|
232
|
+
|
233
|
+
```javascript
|
234
|
+
$ chrome-remote-interface inspect
|
235
|
+
>>> Network.enable()
|
236
|
+
{ result: {} }
|
237
|
+
>>> Network.requestWillBeSent(params => params.request.url)
|
238
|
+
{ 'Network.requestWillBeSent': 'params => params.request.url' }
|
239
|
+
>>> Page.navigate({url: 'https://www.wikipedia.org'})
|
240
|
+
{ 'Network.requestWillBeSent': 'https://www.wikipedia.org/' }
|
241
|
+
{ result: { frameId: '5530.1' } }
|
242
|
+
{ 'Network.requestWillBeSent': 'https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia_wordmark.png' }
|
243
|
+
{ 'Network.requestWillBeSent': 'https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png' }
|
244
|
+
{ 'Network.requestWillBeSent': 'https://www.wikipedia.org/portal/wikipedia.org/assets/js/index-3b68787aa6.js' }
|
245
|
+
{ 'Network.requestWillBeSent': 'https://www.wikipedia.org/portal/wikipedia.org/assets/js/gt-ie9-c84bf66d33.js' }
|
246
|
+
{ 'Network.requestWillBeSent': 'https://www.wikipedia.org/portal/wikipedia.org/assets/img/sprite-bookshelf_icons.png?16ed124e8ca7c5ce9d463e8f99b2064427366360' }
|
247
|
+
{ 'Network.requestWillBeSent': 'https://www.wikipedia.org/portal/wikipedia.org/assets/img/sprite-project-logos.png?9afc01c5efe0a8fb6512c776955e2ad3eb48fbca' }
|
248
|
+
```
|
249
|
+
|
250
|
+
Embedded documentation
|
251
|
+
----------------------
|
252
|
+
|
253
|
+
In both the REPL and the regular API every object of the protocol is *decorated*
|
254
|
+
with the meta information found within the descriptor. In addition The
|
255
|
+
`category` field is added, which determines if the member is a `command`, an
|
256
|
+
`event` or a `type`.
|
257
|
+
|
258
|
+
For example to learn how to call `Page.navigate`:
|
259
|
+
|
260
|
+
```javascript
|
261
|
+
>>> Page.navigate
|
262
|
+
{ [Function]
|
263
|
+
category: 'command',
|
264
|
+
parameters: { url: { type: 'string', description: 'URL to navigate the page to.' } },
|
265
|
+
returns:
|
266
|
+
[ { name: 'frameId',
|
267
|
+
'$ref': 'FrameId',
|
268
|
+
hidden: true,
|
269
|
+
description: 'Frame id that will be navigated.' } ],
|
270
|
+
description: 'Navigates current page to the given URL.',
|
271
|
+
handlers: [ 'browser', 'renderer' ] }
|
272
|
+
```
|
273
|
+
|
274
|
+
To learn about the parameters returned by the `Network.requestWillBeSent` event:
|
275
|
+
|
276
|
+
```javascript
|
277
|
+
>>> Network.requestWillBeSent
|
278
|
+
{ [Function]
|
279
|
+
category: 'event',
|
280
|
+
description: 'Fired when page is about to send HTTP request.',
|
281
|
+
parameters:
|
282
|
+
{ requestId: { '$ref': 'RequestId', description: 'Request identifier.' },
|
283
|
+
frameId:
|
284
|
+
{ '$ref': 'Page.FrameId',
|
285
|
+
description: 'Frame identifier.',
|
286
|
+
hidden: true },
|
287
|
+
loaderId: { '$ref': 'LoaderId', description: 'Loader identifier.' },
|
288
|
+
documentURL:
|
289
|
+
{ type: 'string',
|
290
|
+
description: 'URL of the document this request is loaded for.' },
|
291
|
+
request: { '$ref': 'Request', description: 'Request data.' },
|
292
|
+
timestamp: { '$ref': 'Timestamp', description: 'Timestamp.' },
|
293
|
+
wallTime:
|
294
|
+
{ '$ref': 'Timestamp',
|
295
|
+
hidden: true,
|
296
|
+
description: 'UTC Timestamp.' },
|
297
|
+
initiator: { '$ref': 'Initiator', description: 'Request initiator.' },
|
298
|
+
redirectResponse:
|
299
|
+
{ optional: true,
|
300
|
+
'$ref': 'Response',
|
301
|
+
description: 'Redirect response data.' },
|
302
|
+
type:
|
303
|
+
{ '$ref': 'Page.ResourceType',
|
304
|
+
optional: true,
|
305
|
+
hidden: true,
|
306
|
+
description: 'Type of this resource.' } } }
|
307
|
+
```
|
308
|
+
|
309
|
+
To inspect the `Network.Request` (note that unlike commands and events, types
|
310
|
+
are named in upper camel case) type:
|
311
|
+
|
312
|
+
```javascript
|
313
|
+
>>> Network.Request
|
314
|
+
{ category: 'type',
|
315
|
+
id: 'Request',
|
316
|
+
type: 'object',
|
317
|
+
description: 'HTTP request data.',
|
318
|
+
properties:
|
319
|
+
{ url: { type: 'string', description: 'Request URL.' },
|
320
|
+
method: { type: 'string', description: 'HTTP request method.' },
|
321
|
+
headers: { '$ref': 'Headers', description: 'HTTP request headers.' },
|
322
|
+
postData:
|
323
|
+
{ type: 'string',
|
324
|
+
optional: true,
|
325
|
+
description: 'HTTP POST request data.' },
|
326
|
+
mixedContentType:
|
327
|
+
{ optional: true,
|
328
|
+
type: 'string',
|
329
|
+
enum: [Object],
|
330
|
+
description: 'The mixed content status of the request, as defined in http://www.w3.org/TR/mixed-content/' },
|
331
|
+
initialPriority:
|
332
|
+
{ '$ref': 'ResourcePriority',
|
333
|
+
description: 'Priority of the resource request at the time request is sent.' } } }
|
334
|
+
```
|
335
|
+
|
336
|
+
Chrome Debugging Protocol versions
|
337
|
+
----------------------------------
|
338
|
+
|
339
|
+
`chrome-remote-interface` uses the [local version] of the protocol descriptor by
|
340
|
+
default. This file is manually updated from time to time using
|
341
|
+
`scripts/update-protocol.sh` and pushed to this repository.
|
342
|
+
|
343
|
+
This behavior can be changed by setting the `remote` option to `true`
|
344
|
+
upon [connection](#cdpoptions-callback), in which case the remote instance is
|
345
|
+
*asked* to provide its own protocol descriptor.
|
346
|
+
|
347
|
+
Chrome < 60.0.3097.0 is not able to do that, so in that case the protocol
|
348
|
+
descriptor is fetched from the source repository.
|
349
|
+
|
350
|
+
To override the above behavior there are basically three options:
|
351
|
+
|
352
|
+
- pass a custom protocol descriptor upon [connection](#cdpoptions-callback)
|
353
|
+
(`protocol` option);
|
354
|
+
|
355
|
+
- use the *raw* version of the [commands](#clientsendmethod-params-callback)
|
356
|
+
and [events](#event-domainmethod) interface to use bleeding-edge features that
|
357
|
+
do not appear in the [local version] of the protocol descriptor;
|
358
|
+
|
359
|
+
- update the local copy with `scripts/update-protocol.sh` (not present when
|
360
|
+
fetched with `npm install`).
|
361
|
+
|
362
|
+
[local version]: lib/protocol.json
|
363
|
+
|
364
|
+
Browser usage
|
365
|
+
-------------
|
366
|
+
|
367
|
+
This module is able to run within a web context, with obvious limitations
|
368
|
+
though, namely external HTTP requests
|
369
|
+
([List](#cdplistoptions-callback), [New](#cdpnewoptions-callback), etc.) cannot
|
370
|
+
be performed directly, for this reason the user must provide a global
|
371
|
+
`criRequest` in order to use them:
|
372
|
+
|
373
|
+
```js
|
374
|
+
function criRequest(options, callback) {}
|
375
|
+
```
|
376
|
+
|
377
|
+
`options` is the same object used by the Node.js `http` module and `callback` is
|
378
|
+
a function taking two arguments: `err` (JavaScript `Error` object or `null`) and
|
379
|
+
`data` (string result).
|
380
|
+
|
381
|
+
### Using [webpack](https://webpack.github.io/)
|
382
|
+
|
383
|
+
It just works, simply require this module:
|
384
|
+
|
385
|
+
```js
|
386
|
+
const CDP = require('chrome-remote-interface');
|
387
|
+
```
|
388
|
+
|
389
|
+
To use a non-minified version manually run webpack with:
|
390
|
+
|
391
|
+
DEBUG=true npm run webpack
|
392
|
+
|
393
|
+
### Using *vanilla* JavaScript
|
394
|
+
|
395
|
+
To generate a JavaScript file that can be used with a `<script>` element:
|
396
|
+
|
397
|
+
1. run `npm install` from the root directory;
|
398
|
+
|
399
|
+
2. manually run webpack with:
|
400
|
+
|
401
|
+
TARGET=var npm run webpack
|
402
|
+
TARGET=var DEBUG=true npm run webpack
|
403
|
+
|
404
|
+
3. use as:
|
405
|
+
|
406
|
+
```html
|
407
|
+
<script>
|
408
|
+
function criRequest(options, callback) { /*...*/ }
|
409
|
+
</script>
|
410
|
+
<script src="chrome-remote-interface.js"></script>
|
411
|
+
```
|
412
|
+
|
413
|
+
API
|
414
|
+
---
|
415
|
+
|
416
|
+
The API consists of three parts:
|
417
|
+
|
418
|
+
- *DevTools* methods (for those [implementations](#implementations) that support
|
419
|
+
them, e.g., [List](#cdplistoptions-callback), [New](#cdpnewoptions-callback),
|
420
|
+
etc.);
|
421
|
+
|
422
|
+
- [connection](#cdpoptions-callback) establishment;
|
423
|
+
|
424
|
+
- the actual [protocol interaction](#class-cdp).
|
425
|
+
|
426
|
+
### CDP([options], [callback])
|
427
|
+
|
428
|
+
Connects to a remote instance using the [Chrome Debugging Protocol].
|
429
|
+
|
430
|
+
`options` is an object with the following optional properties:
|
431
|
+
|
432
|
+
- `host`: HTTP frontend host. Defaults to `localhost`;
|
433
|
+
- `port`: HTTP frontend port. Defaults to `9222`;
|
434
|
+
- `secure`: HTTPS/WSS frontend. Defaults to `false`;
|
435
|
+
- `target`: determines which target this client should attach to. The behavior
|
436
|
+
changes according to the type:
|
437
|
+
|
438
|
+
- a `function` that takes the array returned by the `List` method and returns
|
439
|
+
a target or its numeric index relative to the array;
|
440
|
+
- a target `object` like those returned by the `New` and `List` methods;
|
441
|
+
- a `string` representing the raw WebSocket URL, in this case `host` and
|
442
|
+
`port` are not used to fetch the target list, yet they are used to complete
|
443
|
+
the URL if relative;
|
444
|
+
- a `string` representing the target id.
|
445
|
+
|
446
|
+
Defaults to a function which returns the first available target according to
|
447
|
+
the implementation (note that at most one connection can be established to the
|
448
|
+
same target);
|
449
|
+
- `protocol`: [Chrome Debugging Protocol] descriptor object. Defaults to use the
|
450
|
+
protocol chosen according to the `remote` option;
|
451
|
+
- `remote`: a boolean indicating whether the protocol must be fetched *remotely*
|
452
|
+
or if the local version must be used. It has no effect if the `protocol`
|
453
|
+
option is set. Defaults to `false`.
|
454
|
+
|
455
|
+
These options are also valid properties of all the instances of the `CDP`
|
456
|
+
class. In addition to that, the `webSocketUrl` field contains the currently used
|
457
|
+
WebSocket URL.
|
458
|
+
|
459
|
+
`callback` is a listener automatically added to the `connect` event of the
|
460
|
+
returned `EventEmitter`. When `callback` is omitted a `Promise` object is
|
461
|
+
returned which becomes fulfilled if the `connect` event is triggered and
|
462
|
+
rejected if the `error` event is triggered.
|
463
|
+
|
464
|
+
The `EventEmitter` supports the following events:
|
465
|
+
|
466
|
+
#### Event: 'connect'
|
467
|
+
|
468
|
+
```javascript
|
469
|
+
function (client) {}
|
470
|
+
```
|
471
|
+
|
472
|
+
Emitted when the connection to the WebSocket is established.
|
473
|
+
|
474
|
+
`client` is an instance of the `CDP` class.
|
475
|
+
|
476
|
+
#### Event: 'error'
|
477
|
+
|
478
|
+
```javascript
|
479
|
+
function (err) {}
|
480
|
+
```
|
481
|
+
|
482
|
+
Emitted when `http://host:port/json` cannot be reached or if it is not possible
|
483
|
+
to connect to the WebSocket.
|
484
|
+
|
485
|
+
`err` is an instance of `Error`.
|
486
|
+
|
487
|
+
### CDP.Protocol([options], [callback])
|
488
|
+
|
489
|
+
Fetch the [Chrome Debugging Protocol] descriptor.
|
490
|
+
|
491
|
+
`options` is an object with the following optional properties:
|
492
|
+
|
493
|
+
- `host`: HTTP frontend host. Defaults to `localhost`;
|
494
|
+
- `port`: HTTP frontend port. Defaults to `9222`;
|
495
|
+
- `secure`: HTTPS/WSS frontend. Defaults to `false`;
|
496
|
+
- `remote`: a boolean indicating whether the protocol must be fetched *remotely*
|
497
|
+
or if the local version must be returned. If it is not possible to fulfill the
|
498
|
+
request then the local version is used. Defaults to `false`.
|
499
|
+
|
500
|
+
`callback` is executed when the protocol is fetched, it gets the following
|
501
|
+
arguments:
|
502
|
+
|
503
|
+
- `err`: a `Error` object indicating the success status;
|
504
|
+
- `protocol`: an object with the following properties:
|
505
|
+
- `remote`: a boolean indicating whether the returned descriptor is the
|
506
|
+
remote version or not (due to user choice or error);
|
507
|
+
- `descriptor`: the [Chrome Debugging Protocol] descriptor.
|
508
|
+
|
509
|
+
When `callback` is omitted a `Promise` object is returned.
|
510
|
+
|
511
|
+
For example:
|
512
|
+
|
513
|
+
```javascript
|
514
|
+
const CDP = require('chrome-remote-interface');
|
515
|
+
CDP.Protocol(function (err, protocol) {
|
516
|
+
if (!err) {
|
517
|
+
console.log(JSON.stringify(protocol.descriptor, null, 4));
|
518
|
+
}
|
519
|
+
});
|
520
|
+
```
|
521
|
+
|
522
|
+
### CDP.List([options], [callback])
|
523
|
+
|
524
|
+
Request the list of the available open targets/tabs of the remote instance.
|
525
|
+
|
526
|
+
`options` is an object with the following optional properties:
|
527
|
+
|
528
|
+
- `host`: HTTP frontend host. Defaults to `localhost`;
|
529
|
+
- `port`: HTTP frontend port. Defaults to `9222`;
|
530
|
+
- `secure`: HTTPS/WSS frontend. Defaults to `false`.
|
531
|
+
|
532
|
+
`callback` is executed when the list is correctly received, it gets the
|
533
|
+
following arguments:
|
534
|
+
|
535
|
+
- `err`: a `Error` object indicating the success status;
|
536
|
+
- `targets`: the array returned by `http://host:port/json/list` containing the
|
537
|
+
target list.
|
538
|
+
|
539
|
+
When `callback` is omitted a `Promise` object is returned.
|
540
|
+
|
541
|
+
For example:
|
542
|
+
|
543
|
+
```javascript
|
544
|
+
const CDP = require('chrome-remote-interface');
|
545
|
+
CDP.List(function (err, targets) {
|
546
|
+
if (!err) {
|
547
|
+
console.log(targets);
|
548
|
+
}
|
549
|
+
});
|
550
|
+
```
|
551
|
+
|
552
|
+
### CDP.New([options], [callback])
|
553
|
+
|
554
|
+
Create a new target/tab in the remote instance.
|
555
|
+
|
556
|
+
`options` is an object with the following optional properties:
|
557
|
+
|
558
|
+
- `host`: HTTP frontend host. Defaults to `localhost`;
|
559
|
+
- `port`: HTTP frontend port. Defaults to `9222`;
|
560
|
+
- `secure`: HTTPS/WSS frontend. Defaults to `false`;
|
561
|
+
- `url`: URL to load in the new target/tab. Defaults to `about:blank`.
|
562
|
+
|
563
|
+
`callback` is executed when the target is created, it gets the following
|
564
|
+
arguments:
|
565
|
+
|
566
|
+
- `err`: a `Error` object indicating the success status;
|
567
|
+
- `target`: the object returned by `http://host:port/json/new` containing the
|
568
|
+
target.
|
569
|
+
|
570
|
+
When `callback` is omitted a `Promise` object is returned.
|
571
|
+
|
572
|
+
For example:
|
573
|
+
|
574
|
+
```javascript
|
575
|
+
const CDP = require('chrome-remote-interface');
|
576
|
+
CDP.New(function (err, target) {
|
577
|
+
if (!err) {
|
578
|
+
console.log(target);
|
579
|
+
}
|
580
|
+
});
|
581
|
+
```
|
582
|
+
|
583
|
+
### CDP.Activate([options], [callback])
|
584
|
+
|
585
|
+
Activate an open target/tab of the remote instance.
|
586
|
+
|
587
|
+
`options` is an object with the following properties:
|
588
|
+
|
589
|
+
- `host`: HTTP frontend host. Defaults to `localhost`;
|
590
|
+
- `port`: HTTP frontend port. Defaults to `9222`;
|
591
|
+
- `secure`: HTTPS/WSS frontend. Defaults to `false`;
|
592
|
+
- `id`: Target id. Required, no default.
|
593
|
+
|
594
|
+
`callback` is executed when the response to the activation request is
|
595
|
+
received. It gets the following arguments:
|
596
|
+
|
597
|
+
- `err`: a `Error` object indicating the success status;
|
598
|
+
|
599
|
+
When `callback` is omitted a `Promise` object is returned.
|
600
|
+
|
601
|
+
For example:
|
602
|
+
|
603
|
+
```javascript
|
604
|
+
const CDP = require('chrome-remote-interface');
|
605
|
+
CDP.Activate({'id': 'CC46FBFA-3BDA-493B-B2E4-2BE6EB0D97EC'}, function (err) {
|
606
|
+
if (!err) {
|
607
|
+
console.log('target is activated');
|
608
|
+
}
|
609
|
+
});
|
610
|
+
```
|
611
|
+
|
612
|
+
### CDP.Close([options], [callback])
|
613
|
+
|
614
|
+
Close an open target/tab of the remote instance.
|
615
|
+
|
616
|
+
`options` is an object with the following properties:
|
617
|
+
|
618
|
+
- `host`: HTTP frontend host. Defaults to `localhost`;
|
619
|
+
- `port`: HTTP frontend port. Defaults to `9222`;
|
620
|
+
- `secure`: HTTPS/WSS frontend. Defaults to `false`;
|
621
|
+
- `id`: Target id. Required, no default.
|
622
|
+
|
623
|
+
`callback` is executed when the response to the close request is received. It
|
624
|
+
gets the following arguments:
|
625
|
+
|
626
|
+
- `err`: a `Error` object indicating the success status;
|
627
|
+
|
628
|
+
When `callback` is omitted a `Promise` object is returned.
|
629
|
+
|
630
|
+
For example:
|
631
|
+
|
632
|
+
```javascript
|
633
|
+
const CDP = require('chrome-remote-interface');
|
634
|
+
CDP.Close({'id': 'CC46FBFA-3BDA-493B-B2E4-2BE6EB0D97EC'}, function (err) {
|
635
|
+
if (!err) {
|
636
|
+
console.log('target is closing');
|
637
|
+
}
|
638
|
+
});
|
639
|
+
```
|
640
|
+
|
641
|
+
Note that the callback is fired when the target is *queued* for removal, but the
|
642
|
+
actual removal will occur asynchronously.
|
643
|
+
|
644
|
+
### CDP.Version([options], [callback])
|
645
|
+
|
646
|
+
Request version information from the remote instance.
|
647
|
+
|
648
|
+
`options` is an object with the following optional properties:
|
649
|
+
|
650
|
+
- `host`: HTTP frontend host. Defaults to `localhost`;
|
651
|
+
- `port`: HTTP frontend port. Defaults to `9222`;
|
652
|
+
- `secure`: HTTPS/WSS frontend. Defaults to `false`.
|
653
|
+
|
654
|
+
`callback` is executed when the version information is correctly received, it
|
655
|
+
gets the following arguments:
|
656
|
+
|
657
|
+
- `err`: a `Error` object indicating the success status;
|
658
|
+
- `info`: a JSON object returned by `http://host:port/json/version` containing
|
659
|
+
the version information.
|
660
|
+
|
661
|
+
When `callback` is omitted a `Promise` object is returned.
|
662
|
+
|
663
|
+
For example:
|
664
|
+
|
665
|
+
```javascript
|
666
|
+
const CDP = require('chrome-remote-interface');
|
667
|
+
CDP.Version(function (err, info) {
|
668
|
+
if (!err) {
|
669
|
+
console.log(info);
|
670
|
+
}
|
671
|
+
});
|
672
|
+
```
|
673
|
+
|
674
|
+
### Class: CDP
|
675
|
+
|
676
|
+
#### Event: 'event'
|
677
|
+
|
678
|
+
```javascript
|
679
|
+
function (message) {}
|
680
|
+
```
|
681
|
+
|
682
|
+
Emitted when the remote instance sends any notification through the WebSocket.
|
683
|
+
|
684
|
+
`message` is the object received, it has the following properties:
|
685
|
+
|
686
|
+
- `method`: a string describing the notification (e.g.,
|
687
|
+
`'Network.requestWillBeSent'`);
|
688
|
+
- `params`: an object containing the payload.
|
689
|
+
|
690
|
+
Refer to the [Chrome Debugging Protocol] specification for more information.
|
691
|
+
|
692
|
+
For example:
|
693
|
+
|
694
|
+
```javascript
|
695
|
+
client.on('event', function (message) {
|
696
|
+
if (message.method === 'Network.requestWillBeSent') {
|
697
|
+
console.log(message.params);
|
698
|
+
}
|
699
|
+
});
|
700
|
+
```
|
701
|
+
|
702
|
+
#### Event: '`<domain>`.`<method>`'
|
703
|
+
|
704
|
+
```javascript
|
705
|
+
function (params) {}
|
706
|
+
```
|
707
|
+
|
708
|
+
Emitted when the remote instance sends a notification for `<domain>.<method>`
|
709
|
+
through the WebSocket.
|
710
|
+
|
711
|
+
`params` is an object containing the payload.
|
712
|
+
|
713
|
+
This is just a utility event which allows to easily listen for specific
|
714
|
+
notifications (see [`'event'`](#event-event)), for example:
|
715
|
+
|
716
|
+
```javascript
|
717
|
+
client.on('Network.requestWillBeSent', console.log);
|
718
|
+
```
|
719
|
+
|
720
|
+
#### Event: 'ready'
|
721
|
+
|
722
|
+
```javascript
|
723
|
+
function () {}
|
724
|
+
```
|
725
|
+
|
726
|
+
Emitted every time that there are no more pending commands waiting for a
|
727
|
+
response from the remote instance. The interaction is asynchronous so the only
|
728
|
+
way to serialize a sequence of commands is to use the callback provided by
|
729
|
+
the [`send`](#clientsendmethod-params-callback) method. This event acts as a
|
730
|
+
barrier and it is useful to avoid the *callback hell* in certain simple
|
731
|
+
situations.
|
732
|
+
|
733
|
+
Users are encouraged to extensively check the response of each method and should
|
734
|
+
prefer the promises API when dealing with complex asynchronous program flows.
|
735
|
+
|
736
|
+
For example to load a URL only after having enabled the notifications of both
|
737
|
+
`Network` and `Page` domains:
|
738
|
+
|
739
|
+
```javascript
|
740
|
+
client.Network.enable();
|
741
|
+
client.Page.enable();
|
742
|
+
client.once('ready', function () {
|
743
|
+
client.Page.navigate({'url': 'https://github.com'});
|
744
|
+
});
|
745
|
+
```
|
746
|
+
|
747
|
+
In this particular case, not enforcing this kind of serialization may cause that
|
748
|
+
the remote instance does not properly deliver the desired notifications the
|
749
|
+
client.
|
750
|
+
|
751
|
+
|
752
|
+
#### Event: 'disconnect'
|
753
|
+
|
754
|
+
```javascript
|
755
|
+
function () {}
|
756
|
+
```
|
757
|
+
|
758
|
+
Emitted when the instance closes the WebSocket connection.
|
759
|
+
|
760
|
+
This may happen for example when the user opens DevTools or when the tab is
|
761
|
+
closed.
|
762
|
+
|
763
|
+
#### client.send(method, [params], [callback])
|
764
|
+
|
765
|
+
Issue a command to the remote instance.
|
766
|
+
|
767
|
+
`method` is a string describing the command.
|
768
|
+
|
769
|
+
`params` is an object containing the payload.
|
770
|
+
|
771
|
+
`callback` is executed when the remote instance sends a response to this
|
772
|
+
command, it gets the following arguments:
|
773
|
+
|
774
|
+
- `error`: a boolean value indicating the success status, as reported by the
|
775
|
+
remote instance;
|
776
|
+
- `response`: an object containing either the response (`result` field, if
|
777
|
+
`error === false`) or the indication of the error (`error` field, if `error
|
778
|
+
=== true`).
|
779
|
+
|
780
|
+
When `callback` is omitted a `Promise` object is returned instead, with the
|
781
|
+
fulfilled/rejected states implemented according to the `error` parameter.
|
782
|
+
|
783
|
+
In case of low-level WebSocket errors, the `error` parameter contains the
|
784
|
+
originating `Error` object and no `response` is returned.
|
785
|
+
|
786
|
+
Note that the field `id` mentioned in the [Chrome Debugging Protocol]
|
787
|
+
specification is managed internally and it is not exposed to the user.
|
788
|
+
|
789
|
+
For example:
|
790
|
+
|
791
|
+
```javascript
|
792
|
+
client.send('Page.navigate', {'url': 'https://github.com'}, console.log);
|
793
|
+
```
|
794
|
+
|
795
|
+
#### client.`<domain>`.`<method>`([params], [callback])
|
796
|
+
|
797
|
+
Just a shorthand for:
|
798
|
+
|
799
|
+
```javascript
|
800
|
+
client.send('<domain>.<method>', params, callback);
|
801
|
+
```
|
802
|
+
|
803
|
+
For example:
|
804
|
+
|
805
|
+
```javascript
|
806
|
+
client.Page.navigate({'url': 'https://github.com'}, console.log);
|
807
|
+
```
|
808
|
+
|
809
|
+
#### client.`<domain>`.`<event>`([callback])
|
810
|
+
|
811
|
+
Just a shorthand for:
|
812
|
+
|
813
|
+
```javascript
|
814
|
+
client.on('<domain>.<event>', callback);
|
815
|
+
```
|
816
|
+
|
817
|
+
The only difference is that when `callback` is omitted the event is registered
|
818
|
+
only once and a `Promise` object is returned.
|
819
|
+
|
820
|
+
For example:
|
821
|
+
|
822
|
+
```javascript
|
823
|
+
client.Network.requestWillBeSent(console.log);
|
824
|
+
```
|
825
|
+
|
826
|
+
#### client.close([callback])
|
827
|
+
|
828
|
+
Close the connection to the remote instance.
|
829
|
+
|
830
|
+
`callback` is executed when the WebSocket is successfully closed.
|
831
|
+
|
832
|
+
When `callback` is omitted a `Promise` object is returned.
|
833
|
+
|
834
|
+
Contributors
|
835
|
+
------------
|
836
|
+
|
837
|
+
- [Andrey Sidorov](https://github.com/sidorares)
|
838
|
+
- [Greg Cochard](https://github.com/gcochard)
|
839
|
+
|
840
|
+
Resources
|
841
|
+
---------
|
842
|
+
|
843
|
+
- [Chrome Debugging Protocol]
|
844
|
+
- [Chrome Debugging Protocol Google group](https://groups.google.com/forum/#!forum/chrome-debugging-protocol)
|
845
|
+
- [devtools-protocol official repo](https://github.com/ChromeDevTools/devtools-protocol)
|
846
|
+
- [Showcase Chrome Debugging Protocol Clients](https://developer.chrome.com/devtools/docs/debugging-clients)
|
847
|
+
- [Awesome chrome-devtools](https://github.com/ChromeDevTools/awesome-chrome-devtools)
|
848
|
+
|
849
|
+
[Chrome Debugging Protocol]: https://chromedevtools.github.io/devtools-protocol/
|