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.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +17 -0
  3. data/Gemfile +1 -0
  4. data/HACKING.md +47 -26
  5. data/UNRELEASED.md +28 -0
  6. data/benchmark/benchmarks +415 -103
  7. data/benchmark/bm_call_overhead.yml +28 -0
  8. data/benchmark/run.rb +61 -40
  9. data/docs/cdp_common.json +3364 -0
  10. data/docs/cdp_common.md +18 -0
  11. data/docs/{headless_chrome.md → headless_browsers.md} +31 -12
  12. data/lib/opal/ast/builder.rb +1 -1
  13. data/lib/opal/builder.rb +6 -1
  14. data/lib/opal/builder_processors.rb +5 -3
  15. data/lib/opal/cache.rb +1 -7
  16. data/lib/opal/cli_options.rb +72 -58
  17. data/lib/opal/cli_runners/chrome.rb +47 -9
  18. data/lib/opal/cli_runners/chrome_cdp_interface.rb +238 -112
  19. data/lib/opal/cli_runners/compiler.rb +146 -13
  20. data/lib/opal/cli_runners/deno.rb +32 -0
  21. data/lib/opal/cli_runners/firefox.rb +350 -0
  22. data/lib/opal/cli_runners/firefox_cdp_interface.rb +212 -0
  23. data/lib/opal/cli_runners/node_modules/.bin/chrome-remote-interface.cmd +17 -0
  24. data/lib/opal/cli_runners/node_modules/.bin/chrome-remote-interface.ps1 +28 -0
  25. data/lib/opal/cli_runners/node_modules/.package-lock.json +41 -0
  26. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/LICENSE +1 -1
  27. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/README.md +322 -182
  28. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/bin/client.js +99 -114
  29. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/chrome-remote-interface.js +1 -11
  30. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/index.js +16 -11
  31. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/api.js +41 -33
  32. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/chrome.js +224 -214
  33. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/devtools.js +71 -191
  34. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js +26 -6
  35. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/protocol.json +20788 -9049
  36. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +10 -3
  37. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/package.json +59 -123
  38. data/lib/opal/cli_runners/node_modules/chrome-remote-interface/webpack.config.js +25 -32
  39. data/lib/opal/cli_runners/node_modules/commander/History.md +298 -0
  40. data/lib/opal/cli_runners/node_modules/commander/LICENSE +22 -0
  41. data/lib/opal/cli_runners/node_modules/commander/Readme.md +217 -61
  42. data/lib/opal/cli_runners/node_modules/commander/index.js +431 -145
  43. data/lib/opal/cli_runners/node_modules/commander/package.json +16 -79
  44. data/lib/opal/cli_runners/node_modules/ws/README.md +334 -98
  45. data/lib/opal/cli_runners/node_modules/ws/browser.js +8 -0
  46. data/lib/opal/cli_runners/node_modules/ws/index.js +5 -10
  47. data/lib/opal/cli_runners/node_modules/ws/lib/buffer-util.js +129 -0
  48. data/lib/opal/cli_runners/node_modules/ws/lib/constants.js +10 -0
  49. data/lib/opal/cli_runners/node_modules/ws/lib/event-target.js +184 -0
  50. data/lib/opal/cli_runners/node_modules/ws/lib/extension.js +223 -0
  51. data/lib/opal/cli_runners/node_modules/ws/lib/limiter.js +55 -0
  52. data/lib/opal/cli_runners/node_modules/ws/lib/permessage-deflate.js +518 -0
  53. data/lib/opal/cli_runners/node_modules/ws/lib/receiver.js +607 -0
  54. data/lib/opal/cli_runners/node_modules/ws/lib/sender.js +409 -0
  55. data/lib/opal/cli_runners/node_modules/ws/lib/stream.js +180 -0
  56. data/lib/opal/cli_runners/node_modules/ws/lib/validation.js +104 -0
  57. data/lib/opal/cli_runners/node_modules/ws/lib/websocket-server.js +447 -0
  58. data/lib/opal/cli_runners/node_modules/ws/lib/websocket.js +1195 -0
  59. data/lib/opal/cli_runners/node_modules/ws/package.json +40 -106
  60. data/lib/opal/cli_runners/package-lock.json +62 -0
  61. data/lib/opal/cli_runners/package.json +1 -1
  62. data/lib/opal/cli_runners.rb +26 -4
  63. data/lib/opal/nodes/args/prepare_post_args.rb +2 -2
  64. data/lib/opal/nodes/def.rb +8 -8
  65. data/lib/opal/nodes/iter.rb +12 -12
  66. data/lib/opal/nodes/logic.rb +1 -1
  67. data/lib/opal/nodes/masgn.rb +2 -2
  68. data/lib/opal/parser/with_ruby_lexer.rb +1 -1
  69. data/lib/opal/paths.rb +14 -0
  70. data/lib/opal/rewriter.rb +2 -0
  71. data/lib/opal/rewriters/forward_args.rb +52 -4
  72. data/lib/opal/rewriters/targeted_patches.rb +94 -0
  73. data/lib/opal/version.rb +1 -1
  74. data/opal/corelib/basic_object.rb +1 -1
  75. data/opal/corelib/boolean.rb +2 -2
  76. data/opal/corelib/class.rb +11 -0
  77. data/opal/corelib/constants.rb +3 -3
  78. data/opal/corelib/enumerable.rb +4 -0
  79. data/opal/corelib/enumerator.rb +1 -1
  80. data/opal/corelib/hash.rb +2 -2
  81. data/opal/corelib/helpers.rb +1 -1
  82. data/opal/corelib/kernel.rb +3 -3
  83. data/opal/corelib/method.rb +1 -1
  84. data/opal/corelib/module.rb +29 -8
  85. data/opal/corelib/proc.rb +7 -5
  86. data/opal/corelib/runtime.js +141 -78
  87. data/opal/corelib/set.rb +252 -0
  88. data/opal/corelib/string.rb +2 -1
  89. data/opal/corelib/time.rb +2 -2
  90. data/opal/opal.rb +1 -0
  91. data/opal.gemspec +1 -0
  92. data/spec/filters/bugs/array.rb +22 -13
  93. data/spec/filters/bugs/base64.rb +5 -5
  94. data/spec/filters/bugs/basicobject.rb +16 -8
  95. data/spec/filters/bugs/bigdecimal.rb +161 -160
  96. data/spec/filters/bugs/binding.rb +10 -10
  97. data/spec/filters/bugs/class.rb +8 -8
  98. data/spec/filters/bugs/complex.rb +2 -1
  99. data/spec/filters/bugs/date.rb +79 -81
  100. data/spec/filters/bugs/datetime.rb +29 -29
  101. data/spec/filters/bugs/delegate.rb +1 -3
  102. data/spec/filters/bugs/encoding.rb +69 -69
  103. data/spec/filters/bugs/enumerable.rb +22 -20
  104. data/spec/filters/bugs/enumerator.rb +88 -85
  105. data/spec/filters/bugs/exception.rb +46 -40
  106. data/spec/filters/bugs/file.rb +32 -32
  107. data/spec/filters/bugs/float.rb +26 -21
  108. data/spec/filters/bugs/freeze.rb +88 -0
  109. data/spec/filters/bugs/hash.rb +39 -38
  110. data/spec/filters/bugs/integer.rb +57 -44
  111. data/spec/filters/bugs/io.rb +1 -1
  112. data/spec/filters/bugs/kernel.rb +349 -269
  113. data/spec/filters/bugs/language.rb +220 -188
  114. data/spec/filters/bugs/main.rb +5 -3
  115. data/spec/filters/bugs/marshal.rb +38 -38
  116. data/spec/filters/bugs/math.rb +2 -1
  117. data/spec/filters/bugs/method.rb +73 -62
  118. data/spec/filters/bugs/module.rb +163 -143
  119. data/spec/filters/bugs/numeric.rb +6 -6
  120. data/spec/filters/bugs/objectspace.rb +16 -16
  121. data/spec/filters/bugs/openstruct.rb +1 -1
  122. data/spec/filters/bugs/pack_unpack.rb +51 -51
  123. data/spec/filters/bugs/pathname.rb +7 -7
  124. data/spec/filters/bugs/proc.rb +63 -63
  125. data/spec/filters/bugs/random.rb +7 -6
  126. data/spec/filters/bugs/range.rb +12 -9
  127. data/spec/filters/bugs/rational.rb +8 -7
  128. data/spec/filters/bugs/regexp.rb +49 -48
  129. data/spec/filters/bugs/ruby-32.rb +56 -0
  130. data/spec/filters/bugs/set.rb +30 -30
  131. data/spec/filters/bugs/singleton.rb +4 -4
  132. data/spec/filters/bugs/string.rb +187 -99
  133. data/spec/filters/bugs/stringio.rb +7 -0
  134. data/spec/filters/bugs/stringscanner.rb +68 -68
  135. data/spec/filters/bugs/struct.rb +11 -9
  136. data/spec/filters/bugs/symbol.rb +1 -1
  137. data/spec/filters/bugs/time.rb +78 -63
  138. data/spec/filters/bugs/trace_point.rb +4 -4
  139. data/spec/filters/bugs/unboundmethod.rb +32 -17
  140. data/spec/filters/bugs/warnings.rb +8 -12
  141. data/spec/filters/unsupported/array.rb +24 -107
  142. data/spec/filters/unsupported/basicobject.rb +12 -12
  143. data/spec/filters/unsupported/bignum.rb +27 -52
  144. data/spec/filters/unsupported/class.rb +1 -2
  145. data/spec/filters/unsupported/delegator.rb +3 -3
  146. data/spec/filters/unsupported/enumerable.rb +2 -9
  147. data/spec/filters/unsupported/enumerator.rb +2 -11
  148. data/spec/filters/unsupported/file.rb +1 -1
  149. data/spec/filters/unsupported/float.rb +28 -47
  150. data/spec/filters/unsupported/hash.rb +8 -14
  151. data/spec/filters/unsupported/integer.rb +75 -91
  152. data/spec/filters/unsupported/kernel.rb +17 -35
  153. data/spec/filters/unsupported/language.rb +11 -19
  154. data/spec/filters/unsupported/marshal.rb +22 -41
  155. data/spec/filters/unsupported/matchdata.rb +28 -52
  156. data/spec/filters/unsupported/math.rb +1 -1
  157. data/spec/filters/unsupported/privacy.rb +229 -285
  158. data/spec/filters/unsupported/range.rb +1 -5
  159. data/spec/filters/unsupported/regexp.rb +40 -66
  160. data/spec/filters/unsupported/set.rb +2 -2
  161. data/spec/filters/unsupported/singleton.rb +4 -4
  162. data/spec/filters/unsupported/string.rb +305 -508
  163. data/spec/filters/unsupported/struct.rb +3 -4
  164. data/spec/filters/unsupported/symbol.rb +15 -18
  165. data/spec/filters/unsupported/thread.rb +1 -7
  166. data/spec/filters/unsupported/time.rb +159 -202
  167. data/spec/filters/unsupported/usage_of_files.rb +170 -259
  168. data/spec/lib/builder_spec.rb +4 -4
  169. data/spec/lib/rewriters/forward_args_spec.rb +32 -12
  170. data/spec/mspec-opal/runner.rb +2 -0
  171. data/spec/ruby_specs +4 -0
  172. data/stdlib/deno/base.rb +28 -0
  173. data/stdlib/deno/file.rb +340 -0
  174. data/stdlib/{headless_chrome.rb → headless_browser/base.rb} +1 -1
  175. data/stdlib/headless_browser/file.rb +15 -0
  176. data/stdlib/headless_browser.rb +4 -0
  177. data/stdlib/native.rb +1 -1
  178. data/stdlib/nodejs/file.rb +5 -0
  179. data/stdlib/opal/platform.rb +8 -6
  180. data/stdlib/opal-platform.rb +14 -8
  181. data/stdlib/set.rb +1 -258
  182. data/tasks/benchmarking.rake +62 -19
  183. data/tasks/performance.rake +1 -1
  184. data/tasks/testing.rake +5 -3
  185. data/test/nodejs/test_file.rb +29 -10
  186. data/test/opal/http_server.rb +28 -11
  187. data/test/opal/unsupported_and_bugs.rb +2 -1
  188. metadata +91 -52
  189. data/lib/opal/cli_runners/node_modules/ultron/LICENSE +0 -22
  190. data/lib/opal/cli_runners/node_modules/ultron/index.js +0 -138
  191. data/lib/opal/cli_runners/node_modules/ultron/package.json +0 -112
  192. data/lib/opal/cli_runners/node_modules/ws/SECURITY.md +0 -33
  193. data/lib/opal/cli_runners/node_modules/ws/lib/BufferUtil.fallback.js +0 -56
  194. data/lib/opal/cli_runners/node_modules/ws/lib/BufferUtil.js +0 -15
  195. data/lib/opal/cli_runners/node_modules/ws/lib/ErrorCodes.js +0 -28
  196. data/lib/opal/cli_runners/node_modules/ws/lib/EventTarget.js +0 -158
  197. data/lib/opal/cli_runners/node_modules/ws/lib/Extensions.js +0 -69
  198. data/lib/opal/cli_runners/node_modules/ws/lib/PerMessageDeflate.js +0 -339
  199. data/lib/opal/cli_runners/node_modules/ws/lib/Receiver.js +0 -520
  200. data/lib/opal/cli_runners/node_modules/ws/lib/Sender.js +0 -438
  201. data/lib/opal/cli_runners/node_modules/ws/lib/Validation.fallback.js +0 -9
  202. data/lib/opal/cli_runners/node_modules/ws/lib/Validation.js +0 -17
  203. data/lib/opal/cli_runners/node_modules/ws/lib/WebSocket.js +0 -705
  204. data/lib/opal/cli_runners/node_modules/ws/lib/WebSocketServer.js +0 -336
  205. data/spec/filters/bugs/boolean.rb +0 -3
  206. data/spec/filters/bugs/matrix.rb +0 -3
  207. data/spec/filters/unsupported/fixnum.rb +0 -15
  208. data/spec/filters/unsupported/freeze.rb +0 -102
  209. data/spec/filters/unsupported/pathname.rb +0 -4
  210. data/spec/filters/unsupported/proc.rb +0 -4
  211. data/spec/filters/unsupported/random.rb +0 -5
  212. 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
- 'colors': process.stdout.isTTY,
17
- 'depth': null
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.remote = args.remote;
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 = function (targets) {
43
- return targets.findIndex(function (target) {
44
- return target.id === target;
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, function (client) {
55
- // keep track of registered events
56
- const registeredEvents = {};
57
-
49
+ CDP(options, (client) => {
58
50
  const cdpRepl = repl.start({
59
- 'prompt': '\x1b[32m>>>\x1b[0m ',
60
- 'ignoreUndefined': true,
61
- 'writer': display
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(function (entry) {
93
+ .filter((entry) => {
80
94
  return entry.trim();
81
95
  })
82
96
  .reverse() // to be compatible with repl.history files
83
- .forEach(function (entry) {
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
- function overridePrompt(string) {
95
- // hack to get rid of the prompt (clean line and reposition cursor)
96
- console.log('\x1b[2K\x1b[G%s', string);
97
- cdpRepl.displayPrompt(true);
98
- }
99
-
100
- function overrideCommand(command) {
101
- // hard code a callback to display the result
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
- function overrideEvent(client, domainName, itemName) {
115
- const event = client[domainName][itemName];
116
- const eventName = domainName + '.' + itemName;
117
- // hard code a callback to display the event data
118
- const override = function (filter) {
119
- // remove all the listeners (just one actually) anyway
120
- client.removeAllListeners(eventName);
121
- const status = {};
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', function () {
152
- console.log();
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', function () {
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.forEach(function (domainObject) {
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
- Object.keys(client[domainName]).forEach(function (itemName) {
170
- // walk the items in the domain and override commands and events
171
- let item = client[domainName][itemName];
172
- switch (item.category) {
173
- case 'command':
174
- item = overrideCommand(item);
175
- break;
176
- case 'event':
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, function (err, targets) {
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, function (err, target) {
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, function (err) {
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, function (err) {
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, function (err, info) {
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.remote = args.remote;
241
- CDP.Protocol(options, function (err, protocol) {
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 `--remote`)')
264
- .option('-r, --remote', 'Attempt to fetch the protocol descriptor remotely')
265
- .action(function (target, args) {
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(function () {
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(function (url) {
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(function (id) {
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(function (id) {
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(function () {
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('-r, --remote', 'Attempt to fetch the protocol descriptor remotely')
308
- .action(function (args) {
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
- 'host': program.host,
317
- 'port': program.port,
318
- 'secure': program.secure
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.outputHelp();
325
- process.exit(1);
305
+ if (program.v) {
306
+ console.log(packageInfo.version);
307
+ } else {
308
+ program.outputHelp();
309
+ process.exit(1);
310
+ }
326
311
  }