chromedriver 147.0.0 → 147.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/chromedriver.js +37 -26
  2. package/package.json +1 -1
@@ -1,48 +1,59 @@
1
- const fs = require('node:fs');
2
- const path = require('node:path');
3
- const tcpPortUsed = require('tcp-port-used');
1
+ const fs = require("node:fs");
2
+ const path = require("node:path");
3
+ const tcpPortUsed = require("tcp-port-used");
4
4
  function getPortFromArgs(args) {
5
- let port = 9515;
6
- if (!args)
7
- return port;
8
- const portRegexp = /--port=(\d*)/;
5
+ if (!args || args.length === 0) return;
6
+ const portRegexp = /--port=(\d+)/;
9
7
  const portArg = args.find(function (arg) {
10
8
  return portRegexp.test(arg);
11
9
  });
12
- if (portArg)
13
- port = parseInt(portRegexp.exec(portArg)[1]);
10
+ if (!portArg) {
11
+ const catchAllPortRegexp = /--port=(\S+)/;
12
+ const incorrectTypePortArg = args.find(function (arg) {
13
+ return catchAllPortRegexp.test(arg);
14
+ });
15
+ if (incorrectTypePortArg) {
16
+ console.error("Invalid port.");
17
+ process.exit(1);
18
+ } else {
19
+ return;
20
+ }
21
+ }
22
+ const port = parseInt(portRegexp.exec(portArg)[1]);
14
23
  return port;
15
24
  }
16
- process.env.PATH = path.join(__dirname, 'chromedriver') + path.delimiter + process.env.PATH;
17
- const crpath = process.platform === 'win32' ? path.join(__dirname, 'chromedriver', 'chromedriver.exe') : path.join(__dirname, 'chromedriver', 'chromedriver');
18
- const version = '147.0.7727.24';
25
+ process.env.PATH = path.join(__dirname, "chromedriver") + path.delimiter + process.env.PATH;
26
+ const crpath =
27
+ process.platform === "win32"
28
+ ? path.join(__dirname, "chromedriver", "chromedriver.exe")
29
+ : path.join(__dirname, "chromedriver", "chromedriver");
30
+ const version = "147.0.7727.56";
19
31
  let defaultInstance = null;
20
32
 
21
33
  function start(args, returnPromise) {
34
+ args = args || [];
22
35
  let command = crpath;
23
36
  if (!fs.existsSync(command)) {
24
- console.log('Could not find chromedriver in default path: ', command);
25
- console.log('Falling back to use global chromedriver bin');
26
- command = process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver';
37
+ console.log("Could not find chromedriver in default path: ", command);
38
+ console.log("Falling back to use global chromedriver bin");
39
+ command = process.platform === "win32" ? "chromedriver.exe" : "chromedriver";
27
40
  }
28
- const cp = require('child_process').spawn(command, args);
41
+ const port = getPortFromArgs(args);
42
+ if (!port) args.push("--port=9515");
43
+ const cp = require("child_process").spawn(command, args);
29
44
  cp.stdout.pipe(process.stdout);
30
45
  cp.stderr.pipe(process.stderr);
31
46
  defaultInstance = cp;
32
- if (!returnPromise)
33
- return cp;
34
- const port = getPortFromArgs(args);
47
+ if (!returnPromise) return cp;
35
48
  const pollInterval = 100;
36
49
  const timeout = 10000;
37
- return tcpPortUsed.waitUntilUsed(port, pollInterval, timeout)
38
- .then(function () {
39
- return cp;
40
- });
50
+ return tcpPortUsed.waitUntilUsed(port, pollInterval, timeout).then(function () {
51
+ return cp;
52
+ });
41
53
  }
42
54
 
43
55
  function stop() {
44
- if (defaultInstance != null)
45
- defaultInstance.kill();
56
+ if (defaultInstance != null) defaultInstance.kill();
46
57
  defaultInstance = null;
47
58
  }
48
59
 
@@ -53,5 +64,5 @@ module.exports = {
53
64
  stop,
54
65
  get defaultInstance() {
55
66
  return defaultInstance;
56
- }
67
+ },
57
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chromedriver",
3
- "version": "147.0.0",
3
+ "version": "147.0.2",
4
4
  "keywords": [
5
5
  "chromedriver",
6
6
  "selenium"