Skip to content

Commit 00c030a

Browse files
committed
Merge upstream/master into master (0.31.2-lum.14 => 0.33.3-lum.15)
2 parents 078ade6 + e890754 commit 00c030a

File tree

12 files changed

+9895
-7133
lines changed

12 files changed

+9895
-7133
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
workflow_dispatch:
10+
jobs:
11+
Tests:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Dump Chrome version
16+
run: |
17+
"$CHROME_BIN" --version
18+
- name: Dump Node.js version
19+
run: |
20+
node --version
21+
- name: Dump NPM version
22+
run: |
23+
npm --version
24+
- name: Install dependencies
25+
run: |
26+
npm install
27+
- name: Start headless Chrome
28+
run: |
29+
$CHROME_BIN \
30+
--disable-extensions \
31+
--disable-gpu \
32+
--headless \
33+
--no-first-run \
34+
--no-sandbox \
35+
--remote-debugging-port=9222 \
36+
--user-data-dir="$(mktemp -d)" \
37+
about:blank &
38+
- name: Wait for Chrome to start listening
39+
run: |
40+
while ! curl --silent --fail http://localhost:9222; do sleep 1; done
41+
- name: Run tests
42+
run: |
43+
npm test

.travis.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2021 Andrea Cardaci <cyrus.and@gmail.com>
1+
Copyright (c) 2025 Andrea Cardaci <cyrus.and@gmail.com>
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of
44
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
# chrome-remote-interface [![Build Status][]][travis]
1+
# chrome-remote-interface
22

3-
[Build Status]: https://app.travis-ci.com/cyrus-and/chrome-remote-interface.svg?branch=master
4-
[travis]: https://app.travis-ci.com/cyrus-and/chrome-remote-interface
3+
[![CI status](https://github.com/cyrus-and/chrome-remote-interface/actions/workflows/ci.yml/badge.svg)](https://github.com/cyrus-and/chrome-remote-interface/actions?query=workflow:CI)
54

65
[Chrome Debugging Protocol] interface that helps to instrument Chrome (or any
76
other suitable [implementation](#implementations)) by providing a simple
87
abstraction of commands and notifications using a straightforward JavaScript
98
API.
109

11-
This module is one of the many [third-party protocol clients][3rd-party].
12-
13-
[3rd-party]: https://developer.chrome.com/devtools/docs/debugging-clients#chrome-remote-interface
14-
1510
## Sample API usage
1611

1712
The following snippet loads `https://github.com` and dumps every request made:
@@ -131,14 +126,14 @@ Since version 59, additionally use the `--headless` option, for example:
131126

132127
#### Android
133128

134-
Plug the device and enable the [port forwarding][adb], for example:
129+
Plug the device and make sure to authorize the connection from the device itself. Then
130+
enable the port forwarding, for example:
135131

136-
adb forward tcp:9222 localabstract:chrome_devtools_remote
132+
adb -d forward tcp:9222 localabstract:chrome_devtools_remote
137133

138-
Note that in Android, Chrome does not have its own protocol available, a local
139-
version must be used. See [here](#chrome-debugging-protocol-versions) for more information.
140-
141-
[adb]: https://developer.chrome.com/devtools/docs/remote-debugging-legacy
134+
After that you should be able to use `http://127.0.0.1:9222` as usual, but note that in
135+
Android, Chrome does not have its own protocol available, so a local version must be used.
136+
See [here](#chrome-debugging-protocol-versions) for more information.
142137

143138
##### WebView
144139

@@ -400,6 +395,7 @@ To generate a JavaScript file that can be used with a `<script>` element:
400395
</script>
401396
<script src="chrome-remote-interface.js"></script>
402397
```
398+
403399
## TypeScript Support
404400

405401
[TypeScript][] definitions are kindly provided by [Khairul Azhar Kasmiran][] and [Seth Westphal][], and can be installed from [DefinitelyTyped][]:
@@ -408,6 +404,12 @@ To generate a JavaScript file that can be used with a `<script>` element:
408404
npm install --save-dev @types/chrome-remote-interface
409405
```
410406
407+
Note that the TypeScript definitions are automatically generated from the npm package `devtools-protocol@0.0.927104`. For other versions of devtools-protocol:
408+
409+
1. Install patch-package using [the instructions given](https://github.com/ds300/patch-package#set-up).
410+
2. Copy the contents of the corresponding https://github.com/ChromeDevTools/devtools-protocol/tree/master/types folder (according to commit) into `node_modules/devtools-protocol/types`.
411+
3. Run `npx patch-package devtools-protocol` so that the changes persist across an `npm install`.
412+
411413
[TypeScript]: https://www.typescriptlang.org/
412414
[Khairul Azhar Kasmiran]: https://github.com/kazarmy
413415
[Seth Westphal]: https://github.com/westy92

lib/chrome.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ class Chrome extends EventEmitter {
225225
if (this.secure) {
226226
this.webSocketUrl = this.webSocketUrl.replace(/^ws:/i, 'wss:');
227227
}
228-
this._ws = new WebSocket(this.webSocketUrl, [], options);
228+
this._ws = new WebSocket(this.webSocketUrl, [], {
229+
maxPayload: 256 * 1024 * 1024,
230+
perMessageDeflate: false,
231+
followRedirects: true,
232+
...options,
233+
});
229234
} catch (err) {
230235
// handles bad URLs
231236
reject(err);

lib/devtools.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ const defaults = require('./defaults.js');
77
const externalRequest = require('./external-request.js');
88

99
// options.path must be specified; callback(err, data)
10-
function devToolsInterface(options, callback) {
11-
options.host = options.host || defaults.HOST;
12-
options.port = options.port || defaults.PORT;
13-
options.secure = !!(options.secure);
14-
options.useHostName = !!(options.useHostName);
15-
options.alterPath = options.alterPath || ((path) => path);
16-
// allow the user to alter the path
17-
const newOptions = {...options};
18-
newOptions.path = options.alterPath(options.path);
19-
externalRequest(options.secure ? https : http, newOptions, callback);
10+
function devToolsInterface(path, options, callback) {
11+
const transport = options.secure ? https : http;
12+
const requestOptions = {
13+
method: options.method,
14+
host: options.host || defaults.HOST,
15+
port: options.port || defaults.PORT,
16+
useHostName: options.useHostName,
17+
path: (options.alterPath ? options.alterPath(path) : path)
18+
};
19+
externalRequest(transport, requestOptions, callback);
2020
}
2121

2222
// wrapper that allows to return a promise if the callback is omitted, it works
@@ -55,8 +55,7 @@ function Protocol(options, callback) {
5555
return;
5656
}
5757
// try to fetch the protocol remotely
58-
options.path = '/json/protocol';
59-
devToolsInterface(options, (err, descriptor) => {
58+
devToolsInterface('/json/protocol', options, (err, descriptor) => {
6059
if (err) {
6160
callback(err);
6261
} else {
@@ -66,8 +65,7 @@ function Protocol(options, callback) {
6665
}
6766

6867
function List(options, callback) {
69-
options.path = '/json/list';
70-
devToolsInterface(options, (err, tabs) => {
68+
devToolsInterface('/json/list', options, (err, tabs) => {
7169
if (err) {
7270
callback(err);
7371
} else {
@@ -77,12 +75,12 @@ function List(options, callback) {
7775
}
7876

7977
function New(options, callback) {
80-
options.path = '/json/new';
81-
options.method = 'PUT';
78+
let path = '/json/new';
8279
if (Object.prototype.hasOwnProperty.call(options, 'url')) {
83-
options.path += `?${options.url}`;
80+
path += `?${options.url}`;
8481
}
85-
devToolsInterface(options, (err, tab) => {
82+
options.method = options.method || 'PUT'; // see #497
83+
devToolsInterface(path, options, (err, tab) => {
8684
if (err) {
8785
callback(err);
8886
} else {
@@ -92,8 +90,7 @@ function New(options, callback) {
9290
}
9391

9492
function Activate(options, callback) {
95-
options.path = '/json/activate/' + options.id;
96-
devToolsInterface(options, (err) => {
93+
devToolsInterface('/json/activate/' + options.id, options, (err) => {
9794
if (err) {
9895
callback(err);
9996
} else {
@@ -103,8 +100,7 @@ function Activate(options, callback) {
103100
}
104101

105102
function Close(options, callback) {
106-
options.path = '/json/close/' + options.id;
107-
devToolsInterface(options, (err) => {
103+
devToolsInterface('/json/close/' + options.id, options, (err) => {
108104
if (err) {
109105
callback(err);
110106
} else {
@@ -114,8 +110,7 @@ function Close(options, callback) {
114110
}
115111

116112
function Version(options, callback) {
117-
options.path = '/json/version';
118-
devToolsInterface(options, (err, versionInfo) => {
113+
devToolsInterface('/json/version', options, (err, versionInfo) => {
119114
if (err) {
120115
callback(err);
121116
} else {

lib/external-request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ async function externalRequest(transport, options, callback) {
3737
if (!options.useHostName) {
3838
try {
3939
const {address} = await util.promisify(dns.lookup)(options.host);
40-
options = Object.assign({}, options);
4140
options.host = address;
4241
} catch (err) {
4342
callback(err);
4443
return;
4544
}
4645
}
4746
// perform the actual request
48-
const request = transport.get(options, (response) => {
47+
const request = transport.request(options, (response) => {
4948
if (
5049
needRedirect(response, options) &&
5150
makeRedirect(response, transport, options, callback)
@@ -69,6 +68,7 @@ async function externalRequest(transport, options, callback) {
6968
request.abort();
7069
});
7170
request.on('error', callback);
71+
request.end();
7272
}
7373

7474
module.exports = externalRequest;

0 commit comments

Comments
 (0)