chromedriver 147.0.1 → 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.
- package/lib/chromedriver.js +37 -26
- package/package.json +1 -1
package/lib/chromedriver.js
CHANGED
|
@@ -1,48 +1,59 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const tcpPortUsed = require(
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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,
|
|
17
|
-
const crpath =
|
|
18
|
-
|
|
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(
|
|
25
|
-
console.log(
|
|
26
|
-
command = process.platform ===
|
|
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
|
|
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
|
-
|
|
39
|
-
|
|
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
|
};
|