opal 1.6.1 → 1.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +17 -0
- data/Gemfile +1 -0
- data/HACKING.md +47 -26
- data/UNRELEASED.md +28 -0
- data/benchmark/benchmarks +415 -103
- data/benchmark/bm_call_overhead.yml +28 -0
- data/benchmark/run.rb +61 -40
- data/docs/cdp_common.json +3364 -0
- data/docs/cdp_common.md +18 -0
- data/docs/{headless_chrome.md → headless_browsers.md} +31 -12
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/builder.rb +6 -1
- data/lib/opal/builder_processors.rb +5 -3
- data/lib/opal/cache.rb +1 -7
- data/lib/opal/cli_options.rb +72 -58
- data/lib/opal/cli_runners/chrome.rb +47 -9
- data/lib/opal/cli_runners/chrome_cdp_interface.rb +238 -112
- data/lib/opal/cli_runners/compiler.rb +146 -13
- data/lib/opal/cli_runners/deno.rb +32 -0
- data/lib/opal/cli_runners/firefox.rb +350 -0
- data/lib/opal/cli_runners/firefox_cdp_interface.rb +212 -0
- data/lib/opal/cli_runners/node_modules/.bin/chrome-remote-interface.cmd +17 -0
- data/lib/opal/cli_runners/node_modules/.bin/chrome-remote-interface.ps1 +28 -0
- data/lib/opal/cli_runners/node_modules/.package-lock.json +41 -0
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/LICENSE +1 -1
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/README.md +322 -182
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/bin/client.js +99 -114
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/chrome-remote-interface.js +1 -11
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/index.js +16 -11
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/api.js +41 -33
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/chrome.js +224 -214
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/devtools.js +71 -191
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js +26 -6
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/protocol.json +20788 -9049
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +10 -3
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/package.json +59 -123
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/webpack.config.js +25 -32
- data/lib/opal/cli_runners/node_modules/commander/History.md +298 -0
- data/lib/opal/cli_runners/node_modules/commander/LICENSE +22 -0
- data/lib/opal/cli_runners/node_modules/commander/Readme.md +217 -61
- data/lib/opal/cli_runners/node_modules/commander/index.js +431 -145
- data/lib/opal/cli_runners/node_modules/commander/package.json +16 -79
- data/lib/opal/cli_runners/node_modules/ws/README.md +334 -98
- data/lib/opal/cli_runners/node_modules/ws/browser.js +8 -0
- data/lib/opal/cli_runners/node_modules/ws/index.js +5 -10
- data/lib/opal/cli_runners/node_modules/ws/lib/buffer-util.js +129 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/constants.js +10 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/event-target.js +184 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/extension.js +223 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/limiter.js +55 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/permessage-deflate.js +518 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/receiver.js +607 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/sender.js +409 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/stream.js +180 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/validation.js +104 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/websocket-server.js +447 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/websocket.js +1195 -0
- data/lib/opal/cli_runners/node_modules/ws/package.json +40 -106
- data/lib/opal/cli_runners/package-lock.json +62 -0
- data/lib/opal/cli_runners/package.json +1 -1
- data/lib/opal/cli_runners.rb +26 -4
- data/lib/opal/nodes/args/prepare_post_args.rb +2 -2
- data/lib/opal/nodes/def.rb +8 -8
- data/lib/opal/nodes/iter.rb +12 -12
- data/lib/opal/nodes/logic.rb +1 -1
- data/lib/opal/nodes/masgn.rb +2 -2
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/paths.rb +14 -0
- data/lib/opal/rewriter.rb +2 -0
- data/lib/opal/rewriters/forward_args.rb +52 -4
- data/lib/opal/rewriters/targeted_patches.rb +94 -0
- data/lib/opal/version.rb +1 -1
- data/opal/corelib/basic_object.rb +1 -1
- data/opal/corelib/boolean.rb +2 -2
- data/opal/corelib/class.rb +11 -0
- data/opal/corelib/constants.rb +3 -3
- data/opal/corelib/enumerable.rb +4 -0
- data/opal/corelib/enumerator.rb +1 -1
- data/opal/corelib/hash.rb +2 -2
- data/opal/corelib/helpers.rb +1 -1
- data/opal/corelib/kernel.rb +3 -3
- data/opal/corelib/method.rb +1 -1
- data/opal/corelib/module.rb +29 -8
- data/opal/corelib/proc.rb +7 -5
- data/opal/corelib/runtime.js +141 -78
- data/opal/corelib/set.rb +252 -0
- data/opal/corelib/string.rb +2 -1
- data/opal/corelib/time.rb +2 -2
- data/opal/opal.rb +1 -0
- data/opal.gemspec +1 -0
- data/spec/filters/bugs/array.rb +22 -13
- data/spec/filters/bugs/base64.rb +5 -5
- data/spec/filters/bugs/basicobject.rb +16 -8
- data/spec/filters/bugs/bigdecimal.rb +161 -160
- data/spec/filters/bugs/binding.rb +10 -10
- data/spec/filters/bugs/class.rb +8 -8
- data/spec/filters/bugs/complex.rb +2 -1
- data/spec/filters/bugs/date.rb +79 -81
- data/spec/filters/bugs/datetime.rb +29 -29
- data/spec/filters/bugs/delegate.rb +1 -3
- data/spec/filters/bugs/encoding.rb +69 -69
- data/spec/filters/bugs/enumerable.rb +22 -20
- data/spec/filters/bugs/enumerator.rb +88 -85
- data/spec/filters/bugs/exception.rb +46 -40
- data/spec/filters/bugs/file.rb +32 -32
- data/spec/filters/bugs/float.rb +26 -21
- data/spec/filters/bugs/freeze.rb +88 -0
- data/spec/filters/bugs/hash.rb +39 -38
- data/spec/filters/bugs/integer.rb +57 -44
- data/spec/filters/bugs/io.rb +1 -1
- data/spec/filters/bugs/kernel.rb +349 -269
- data/spec/filters/bugs/language.rb +220 -188
- data/spec/filters/bugs/main.rb +5 -3
- data/spec/filters/bugs/marshal.rb +38 -38
- data/spec/filters/bugs/math.rb +2 -1
- data/spec/filters/bugs/method.rb +73 -62
- data/spec/filters/bugs/module.rb +163 -143
- data/spec/filters/bugs/numeric.rb +6 -6
- data/spec/filters/bugs/objectspace.rb +16 -16
- data/spec/filters/bugs/openstruct.rb +1 -1
- data/spec/filters/bugs/pack_unpack.rb +51 -51
- data/spec/filters/bugs/pathname.rb +7 -7
- data/spec/filters/bugs/proc.rb +63 -63
- data/spec/filters/bugs/random.rb +7 -6
- data/spec/filters/bugs/range.rb +12 -9
- data/spec/filters/bugs/rational.rb +8 -7
- data/spec/filters/bugs/regexp.rb +49 -48
- data/spec/filters/bugs/ruby-32.rb +56 -0
- data/spec/filters/bugs/set.rb +30 -30
- data/spec/filters/bugs/singleton.rb +4 -4
- data/spec/filters/bugs/string.rb +187 -99
- data/spec/filters/bugs/stringio.rb +7 -0
- data/spec/filters/bugs/stringscanner.rb +68 -68
- data/spec/filters/bugs/struct.rb +11 -9
- data/spec/filters/bugs/symbol.rb +1 -1
- data/spec/filters/bugs/time.rb +78 -63
- data/spec/filters/bugs/trace_point.rb +4 -4
- data/spec/filters/bugs/unboundmethod.rb +32 -17
- data/spec/filters/bugs/warnings.rb +8 -12
- data/spec/filters/unsupported/array.rb +24 -107
- data/spec/filters/unsupported/basicobject.rb +12 -12
- data/spec/filters/unsupported/bignum.rb +27 -52
- data/spec/filters/unsupported/class.rb +1 -2
- data/spec/filters/unsupported/delegator.rb +3 -3
- data/spec/filters/unsupported/enumerable.rb +2 -9
- data/spec/filters/unsupported/enumerator.rb +2 -11
- data/spec/filters/unsupported/file.rb +1 -1
- data/spec/filters/unsupported/float.rb +28 -47
- data/spec/filters/unsupported/hash.rb +8 -14
- data/spec/filters/unsupported/integer.rb +75 -91
- data/spec/filters/unsupported/kernel.rb +17 -35
- data/spec/filters/unsupported/language.rb +11 -19
- data/spec/filters/unsupported/marshal.rb +22 -41
- data/spec/filters/unsupported/matchdata.rb +28 -52
- data/spec/filters/unsupported/math.rb +1 -1
- data/spec/filters/unsupported/privacy.rb +229 -285
- data/spec/filters/unsupported/range.rb +1 -5
- data/spec/filters/unsupported/regexp.rb +40 -66
- data/spec/filters/unsupported/set.rb +2 -2
- data/spec/filters/unsupported/singleton.rb +4 -4
- data/spec/filters/unsupported/string.rb +305 -508
- data/spec/filters/unsupported/struct.rb +3 -4
- data/spec/filters/unsupported/symbol.rb +15 -18
- data/spec/filters/unsupported/thread.rb +1 -7
- data/spec/filters/unsupported/time.rb +159 -202
- data/spec/filters/unsupported/usage_of_files.rb +170 -259
- data/spec/lib/builder_spec.rb +4 -4
- data/spec/lib/rewriters/forward_args_spec.rb +32 -12
- data/spec/mspec-opal/runner.rb +2 -0
- data/spec/ruby_specs +4 -0
- data/stdlib/deno/base.rb +28 -0
- data/stdlib/deno/file.rb +340 -0
- data/stdlib/{headless_chrome.rb → headless_browser/base.rb} +1 -1
- data/stdlib/headless_browser/file.rb +15 -0
- data/stdlib/headless_browser.rb +4 -0
- data/stdlib/native.rb +1 -1
- data/stdlib/nodejs/file.rb +5 -0
- data/stdlib/opal/platform.rb +8 -6
- data/stdlib/opal-platform.rb +14 -8
- data/stdlib/set.rb +1 -258
- data/tasks/benchmarking.rake +62 -19
- data/tasks/performance.rake +1 -1
- data/tasks/testing.rake +5 -3
- data/test/nodejs/test_file.rb +29 -10
- data/test/opal/http_server.rb +28 -11
- data/test/opal/unsupported_and_bugs.rb +2 -1
- metadata +91 -52
- data/lib/opal/cli_runners/node_modules/ultron/LICENSE +0 -22
- data/lib/opal/cli_runners/node_modules/ultron/index.js +0 -138
- data/lib/opal/cli_runners/node_modules/ultron/package.json +0 -112
- data/lib/opal/cli_runners/node_modules/ws/SECURITY.md +0 -33
- data/lib/opal/cli_runners/node_modules/ws/lib/BufferUtil.fallback.js +0 -56
- data/lib/opal/cli_runners/node_modules/ws/lib/BufferUtil.js +0 -15
- data/lib/opal/cli_runners/node_modules/ws/lib/ErrorCodes.js +0 -28
- data/lib/opal/cli_runners/node_modules/ws/lib/EventTarget.js +0 -158
- data/lib/opal/cli_runners/node_modules/ws/lib/Extensions.js +0 -69
- data/lib/opal/cli_runners/node_modules/ws/lib/PerMessageDeflate.js +0 -339
- data/lib/opal/cli_runners/node_modules/ws/lib/Receiver.js +0 -520
- data/lib/opal/cli_runners/node_modules/ws/lib/Sender.js +0 -438
- data/lib/opal/cli_runners/node_modules/ws/lib/Validation.fallback.js +0 -9
- data/lib/opal/cli_runners/node_modules/ws/lib/Validation.js +0 -17
- data/lib/opal/cli_runners/node_modules/ws/lib/WebSocket.js +0 -705
- data/lib/opal/cli_runners/node_modules/ws/lib/WebSocketServer.js +0 -336
- data/spec/filters/bugs/boolean.rb +0 -3
- data/spec/filters/bugs/matrix.rb +0 -3
- data/spec/filters/unsupported/fixnum.rb +0 -15
- data/spec/filters/unsupported/freeze.rb +0 -102
- data/spec/filters/unsupported/pathname.rb +0 -4
- data/spec/filters/unsupported/proc.rb +0 -4
- data/spec/filters/unsupported/random.rb +0 -5
- data/spec/filters/unsupported/taint.rb +0 -162
@@ -10,11 +10,12 @@ const path = require('path');
|
|
10
10
|
const program = require('commander');
|
11
11
|
|
12
12
|
const CDP = require('../');
|
13
|
+
const packageInfo = require('../package.json');
|
13
14
|
|
14
15
|
function display(object) {
|
15
16
|
return util.inspect(object, {
|
16
|
-
|
17
|
-
|
17
|
+
colors: process.stdout.isTTY,
|
18
|
+
depth: null
|
18
19
|
});
|
19
20
|
}
|
20
21
|
|
@@ -22,16 +23,10 @@ function toJSON(object) {
|
|
22
23
|
return JSON.stringify(object, null, 4);
|
23
24
|
}
|
24
25
|
|
25
|
-
function inheritProperties(from, to) {
|
26
|
-
Object.keys(from).forEach(function (property) {
|
27
|
-
to[property] = from[property];
|
28
|
-
});
|
29
|
-
}
|
30
|
-
|
31
26
|
///
|
32
27
|
|
33
28
|
function inspect(target, args, options) {
|
34
|
-
options.
|
29
|
+
options.local = args.local;
|
35
30
|
// otherwise the active target
|
36
31
|
if (target) {
|
37
32
|
if (args.webSocket) {
|
@@ -39,9 +34,9 @@ function inspect(target, args, options) {
|
|
39
34
|
options.target = target;
|
40
35
|
} else {
|
41
36
|
// by target id
|
42
|
-
options.target =
|
43
|
-
return targets.findIndex(
|
44
|
-
return
|
37
|
+
options.target = (targets) => {
|
38
|
+
return targets.findIndex((_target) => {
|
39
|
+
return _target.id === target;
|
45
40
|
});
|
46
41
|
};
|
47
42
|
}
|
@@ -51,21 +46,40 @@ function inspect(target, args, options) {
|
|
51
46
|
options.protocol = JSON.parse(fs.readFileSync(args.protocol));
|
52
47
|
}
|
53
48
|
|
54
|
-
CDP(options,
|
55
|
-
// keep track of registered events
|
56
|
-
const registeredEvents = {};
|
57
|
-
|
49
|
+
CDP(options, (client) => {
|
58
50
|
const cdpRepl = repl.start({
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
prompt: process.stdin.isTTY ? '\x1b[32m>>>\x1b[0m ' : '',
|
52
|
+
ignoreUndefined: true,
|
53
|
+
writer: display
|
62
54
|
});
|
63
55
|
|
56
|
+
// XXX always await promises on the REPL
|
57
|
+
const defaultEval = cdpRepl.eval;
|
58
|
+
cdpRepl.eval = (cmd, context, filename, callback) => {
|
59
|
+
defaultEval(cmd, context, filename, async (err, result) => {
|
60
|
+
if (err) {
|
61
|
+
// propagate errors from the eval
|
62
|
+
callback(err);
|
63
|
+
} else {
|
64
|
+
// awaits the promise and either return result or error
|
65
|
+
try {
|
66
|
+
callback(null, await Promise.resolve(result));
|
67
|
+
} catch (err) {
|
68
|
+
callback(err);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
});
|
72
|
+
};
|
73
|
+
|
64
74
|
const homePath = process.env.HOME || process.env.USERPROFILE;
|
65
75
|
const historyFile = path.join(homePath, '.cri_history');
|
66
76
|
const historySize = 10000;
|
67
77
|
|
68
78
|
function loadHistory() {
|
79
|
+
// only if run from a terminal
|
80
|
+
if (!process.stdin.isTTY) {
|
81
|
+
return;
|
82
|
+
}
|
69
83
|
// attempt to open the history file
|
70
84
|
let fd;
|
71
85
|
try {
|
@@ -76,117 +90,81 @@ function inspect(target, args, options) {
|
|
76
90
|
// populate the REPL history
|
77
91
|
fs.readFileSync(fd, 'utf8')
|
78
92
|
.split('\n')
|
79
|
-
.filter(
|
93
|
+
.filter((entry) => {
|
80
94
|
return entry.trim();
|
81
95
|
})
|
82
96
|
.reverse() // to be compatible with repl.history files
|
83
|
-
.forEach(
|
97
|
+
.forEach((entry) => {
|
84
98
|
cdpRepl.history.push(entry);
|
85
99
|
});
|
86
100
|
}
|
87
101
|
|
88
102
|
function saveHistory() {
|
103
|
+
// only if run from a terminal
|
104
|
+
if (!process.stdin.isTTY) {
|
105
|
+
return;
|
106
|
+
}
|
89
107
|
// only store the last chunk
|
90
108
|
const entries = cdpRepl.history.slice(0, historySize).reverse().join('\n');
|
91
109
|
fs.writeFileSync(historyFile, entries + '\n');
|
92
110
|
}
|
93
111
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
const override = function (params) {
|
103
|
-
command(params, function (error, response) {
|
104
|
-
const repr = {};
|
105
|
-
repr[error ? 'error' : 'result'] = response;
|
106
|
-
overridePrompt(display(repr));
|
107
|
-
});
|
108
|
-
};
|
109
|
-
// inherit the doc decorations
|
110
|
-
inheritProperties(command, override);
|
111
|
-
return override;
|
112
|
-
}
|
112
|
+
// utility custom command
|
113
|
+
cdpRepl.defineCommand('target', {
|
114
|
+
help: 'Display the current target',
|
115
|
+
action: () => {
|
116
|
+
console.log(client.webSocketUrl);
|
117
|
+
cdpRepl.displayPrompt();
|
118
|
+
}
|
119
|
+
});
|
113
120
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
// a filter will always enable/update the listener
|
123
|
-
if (!filter && registeredEvents[eventName]) {
|
124
|
-
delete registeredEvents[eventName];
|
125
|
-
status[eventName] = false;
|
126
|
-
} else {
|
127
|
-
// use the filter (or true) as a status token
|
128
|
-
const statusToken = (filter ? filter.toString() : true);
|
129
|
-
status[eventName] = registeredEvents[eventName] = statusToken;
|
130
|
-
event(function (params) {
|
131
|
-
const repr = {};
|
132
|
-
if (filter) {
|
133
|
-
params = filter(params);
|
134
|
-
}
|
135
|
-
repr[eventName] = params;
|
136
|
-
overridePrompt(display(repr));
|
137
|
-
});
|
138
|
-
}
|
139
|
-
// show the registration status to the user
|
140
|
-
return status;
|
141
|
-
};
|
142
|
-
// inherit the doc decorations
|
143
|
-
inheritProperties(event, override);
|
144
|
-
return override;
|
145
|
-
}
|
121
|
+
// utility to purge all the event handlers
|
122
|
+
cdpRepl.defineCommand('reset', {
|
123
|
+
help: 'Remove all the registered event handlers',
|
124
|
+
action: () => {
|
125
|
+
client.removeAllListeners();
|
126
|
+
cdpRepl.displayPrompt();
|
127
|
+
}
|
128
|
+
});
|
146
129
|
|
147
130
|
// enable history
|
148
131
|
loadHistory();
|
149
132
|
|
150
133
|
// disconnect on exit
|
151
|
-
cdpRepl.on('exit',
|
152
|
-
|
134
|
+
cdpRepl.on('exit', () => {
|
135
|
+
if (process.stdin.isTTY) {
|
136
|
+
console.log();
|
137
|
+
}
|
153
138
|
client.close();
|
154
139
|
saveHistory();
|
155
140
|
});
|
156
141
|
|
157
142
|
// exit on disconnection
|
158
|
-
client.on('disconnect',
|
143
|
+
client.on('disconnect', () => {
|
159
144
|
console.error('Disconnected.');
|
160
145
|
saveHistory();
|
161
146
|
process.exit(1);
|
162
147
|
});
|
163
148
|
|
164
149
|
// add protocol API
|
165
|
-
client.protocol.domains
|
150
|
+
for (const domainObject of client.protocol.domains) {
|
166
151
|
// walk the domain names
|
167
152
|
const domainName = domainObject.domain;
|
168
153
|
cdpRepl.context[domainName] = {};
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
item = overrideEvent(client, domainName, itemName);
|
178
|
-
break;
|
179
|
-
}
|
180
|
-
cdpRepl.context[domainName][itemName] = item;
|
181
|
-
});
|
182
|
-
});
|
183
|
-
}).on('error', function (err) {
|
154
|
+
// walk the items in the domain
|
155
|
+
for (const itemName in client[domainName]) {
|
156
|
+
// add CDP object to the REPL context
|
157
|
+
const cdpObject = client[domainName][itemName];
|
158
|
+
cdpRepl.context[domainName][itemName] = cdpObject;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}).on('error', (err) => {
|
184
162
|
console.error('Cannot connect to remote endpoint:', err.toString());
|
185
163
|
});
|
186
164
|
}
|
187
165
|
|
188
166
|
function list(options) {
|
189
|
-
CDP.List(options,
|
167
|
+
CDP.List(options, (err, targets) => {
|
190
168
|
if (err) {
|
191
169
|
console.error(err.toString());
|
192
170
|
process.exit(1);
|
@@ -197,7 +175,7 @@ function list(options) {
|
|
197
175
|
|
198
176
|
function _new(url, options) {
|
199
177
|
options.url = url;
|
200
|
-
CDP.New(options,
|
178
|
+
CDP.New(options, (err, target) => {
|
201
179
|
if (err) {
|
202
180
|
console.error(err.toString());
|
203
181
|
process.exit(1);
|
@@ -208,7 +186,7 @@ function _new(url, options) {
|
|
208
186
|
|
209
187
|
function activate(args, options) {
|
210
188
|
options.id = args;
|
211
|
-
CDP.Activate(options,
|
189
|
+
CDP.Activate(options, (err) => {
|
212
190
|
if (err) {
|
213
191
|
console.error(err.toString());
|
214
192
|
process.exit(1);
|
@@ -218,7 +196,7 @@ function activate(args, options) {
|
|
218
196
|
|
219
197
|
function close(args, options) {
|
220
198
|
options.id = args;
|
221
|
-
CDP.Close(options,
|
199
|
+
CDP.Close(options, (err) => {
|
222
200
|
if (err) {
|
223
201
|
console.error(err.toString());
|
224
202
|
process.exit(1);
|
@@ -227,7 +205,7 @@ function close(args, options) {
|
|
227
205
|
}
|
228
206
|
|
229
207
|
function version(options) {
|
230
|
-
CDP.Version(options,
|
208
|
+
CDP.Version(options, (err, info) => {
|
231
209
|
if (err) {
|
232
210
|
console.error(err.toString());
|
233
211
|
process.exit(1);
|
@@ -237,8 +215,8 @@ function version(options) {
|
|
237
215
|
}
|
238
216
|
|
239
217
|
function protocol(args, options) {
|
240
|
-
options.
|
241
|
-
CDP.Protocol(options,
|
218
|
+
options.local = args.local;
|
219
|
+
CDP.Protocol(options, (err, protocol) => {
|
242
220
|
if (err) {
|
243
221
|
console.error(err.toString());
|
244
222
|
process.exit(1);
|
@@ -252,60 +230,62 @@ function protocol(args, options) {
|
|
252
230
|
let action;
|
253
231
|
|
254
232
|
program
|
233
|
+
.option('-v, --v', 'Show this module version')
|
255
234
|
.option('-t, --host <host>', 'HTTP frontend host')
|
256
235
|
.option('-p, --port <port>', 'HTTP frontend port')
|
257
|
-
.option('-s, --secure', 'HTTPS/WSS frontend')
|
236
|
+
.option('-s, --secure', 'HTTPS/WSS frontend')
|
237
|
+
.option('-n, --use-host-name', 'Do not perform a DNS lookup of the host');
|
258
238
|
|
259
239
|
program
|
260
240
|
.command('inspect [<target>]')
|
261
241
|
.description('inspect a target (defaults to the first available target)')
|
262
242
|
.option('-w, --web-socket', 'interpret <target> as a WebSocket URL instead of a target id')
|
263
|
-
.option('-j, --protocol <file.json>', 'Chrome Debugging Protocol descriptor (overrides `--
|
264
|
-
.option('-
|
265
|
-
.action(
|
243
|
+
.option('-j, --protocol <file.json>', 'Chrome Debugging Protocol descriptor (overrides `--local`)')
|
244
|
+
.option('-l, --local', 'Use the local protocol descriptor')
|
245
|
+
.action((target, args) => {
|
266
246
|
action = inspect.bind(null, target, args);
|
267
247
|
});
|
268
248
|
|
269
249
|
program
|
270
250
|
.command('list')
|
271
251
|
.description('list all the available targets/tabs')
|
272
|
-
.action(
|
252
|
+
.action(() => {
|
273
253
|
action = list;
|
274
254
|
});
|
275
255
|
|
276
256
|
program
|
277
257
|
.command('new [<url>]')
|
278
258
|
.description('create a new target/tab')
|
279
|
-
.action(
|
259
|
+
.action((url) => {
|
280
260
|
action = _new.bind(null, url);
|
281
261
|
});
|
282
262
|
|
283
263
|
program
|
284
264
|
.command('activate <id>')
|
285
265
|
.description('activate a target/tab by id')
|
286
|
-
.action(
|
266
|
+
.action((id) => {
|
287
267
|
action = activate.bind(null, id);
|
288
268
|
});
|
289
269
|
|
290
270
|
program
|
291
271
|
.command('close <id>')
|
292
272
|
.description('close a target/tab by id')
|
293
|
-
.action(
|
273
|
+
.action((id) => {
|
294
274
|
action = close.bind(null, id);
|
295
275
|
});
|
296
276
|
|
297
277
|
program
|
298
278
|
.command('version')
|
299
279
|
.description('show the browser version')
|
300
|
-
.action(
|
280
|
+
.action(() => {
|
301
281
|
action = version;
|
302
282
|
});
|
303
283
|
|
304
284
|
program
|
305
285
|
.command('protocol')
|
306
286
|
.description('show the currently available protocol descriptor')
|
307
|
-
.option('-
|
308
|
-
.action(
|
287
|
+
.option('-l, --local', 'Return the local protocol descriptor')
|
288
|
+
.action((args) => {
|
309
289
|
action = protocol.bind(null, args);
|
310
290
|
});
|
311
291
|
|
@@ -313,14 +293,19 @@ program.parse(process.argv);
|
|
313
293
|
|
314
294
|
// common options
|
315
295
|
const options = {
|
316
|
-
|
317
|
-
|
318
|
-
|
296
|
+
host: program.host,
|
297
|
+
port: program.port,
|
298
|
+
secure: program.secure,
|
299
|
+
useHostName: program.useHostName
|
319
300
|
};
|
320
301
|
|
321
302
|
if (action) {
|
322
303
|
action(options);
|
323
304
|
} else {
|
324
|
-
program.
|
325
|
-
|
305
|
+
if (program.v) {
|
306
|
+
console.log(packageInfo.version);
|
307
|
+
} else {
|
308
|
+
program.outputHelp();
|
309
|
+
process.exit(1);
|
310
|
+
}
|
326
311
|
}
|