single-file-cli 2.0.29 → 2.0.31
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/deno.json +1 -1
- package/lib/browser.js +26 -3
- package/lib/cdp-client.js +6 -12
- package/lib/constants.js +0 -2
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/single-file-cli-api.js +1 -1
- package/single-file-launcher.js +10 -2
package/deno.json
CHANGED
package/lib/browser.js
CHANGED
|
@@ -25,6 +25,8 @@ import { BROWSER_PATHS, BROWSER_ARGS } from "./constants.js";
|
|
|
25
25
|
import { Deno } from "./deno-polyfill.js";
|
|
26
26
|
|
|
27
27
|
const PIPED_STD_CONFIG = "piped";
|
|
28
|
+
const DEBUG_PORT_MIN = 9222;
|
|
29
|
+
const DEBUG_PORT_RANGE = 256;
|
|
28
30
|
|
|
29
31
|
const { build, makeTempDir, Command, errors, remove } = Deno;
|
|
30
32
|
let child, profilePath;
|
|
@@ -32,7 +34,9 @@ export { launchBrowser, closeBrowser };
|
|
|
32
34
|
|
|
33
35
|
async function launchBrowser(options = {}, indexPath = 0) {
|
|
34
36
|
const executablePath = options.executablePath || BROWSER_PATHS[build.os][indexPath];
|
|
35
|
-
|
|
37
|
+
let args = Array.from(BROWSER_ARGS);
|
|
38
|
+
const debugPort = await getDebugPort();
|
|
39
|
+
args.push("--remote-debugging-port=" + debugPort);
|
|
36
40
|
profilePath = await makeTempDir();
|
|
37
41
|
if (options.headless && !options.debug) {
|
|
38
42
|
args.push("--headless");
|
|
@@ -56,6 +60,8 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
56
60
|
}
|
|
57
61
|
args.push("--user-data-dir=" + profilePath);
|
|
58
62
|
if (options.args) {
|
|
63
|
+
const argNames = options.args.map(arg => arg.split("=")[0]);
|
|
64
|
+
args = args.filter(arg => !argNames.includes(arg.split("=")[0]));
|
|
59
65
|
args.push(...options.args);
|
|
60
66
|
}
|
|
61
67
|
const command = new Command(executablePath, { args, stdout: PIPED_STD_CONFIG, stderr: PIPED_STD_CONFIG });
|
|
@@ -64,7 +70,7 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
64
70
|
} catch (error) {
|
|
65
71
|
if (error instanceof errors.NotFound) {
|
|
66
72
|
if (indexPath + 1 < BROWSER_PATHS[build.os].length) {
|
|
67
|
-
|
|
73
|
+
return launchBrowser(options, indexPath + 1);
|
|
68
74
|
} else {
|
|
69
75
|
throw error;
|
|
70
76
|
}
|
|
@@ -73,7 +79,24 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
81
|
child.ref();
|
|
76
|
-
return
|
|
82
|
+
return debugPort;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function getDebugPort(port = 9222, usedPorts = []) {
|
|
86
|
+
try {
|
|
87
|
+
await fetch("http://localhost:" + port + "/json/version");
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return port;
|
|
90
|
+
}
|
|
91
|
+
if (usedPorts.length < DEBUG_PORT_RANGE) {
|
|
92
|
+
usedPorts.push(port);
|
|
93
|
+
do {
|
|
94
|
+
port = Math.floor(Math.random() * DEBUG_PORT_RANGE) + DEBUG_PORT_MIN;
|
|
95
|
+
} while (usedPorts.includes(port));
|
|
96
|
+
return getDebugPort(port, usedPorts);
|
|
97
|
+
} else {
|
|
98
|
+
throw new Error("No available debugging port");
|
|
99
|
+
}
|
|
77
100
|
}
|
|
78
101
|
|
|
79
102
|
async function closeBrowser() {
|
package/lib/cdp-client.js
CHANGED
|
@@ -25,22 +25,21 @@
|
|
|
25
25
|
|
|
26
26
|
import { launchBrowser, closeBrowser } from "./browser.js";
|
|
27
27
|
import { getScriptSource, getHookScriptSource } from "./single-file-script.js";
|
|
28
|
-
import { CDP } from "simple-cdp";
|
|
28
|
+
import { CDP, options } from "simple-cdp";
|
|
29
29
|
|
|
30
30
|
const LOAD_TIMEOUT_ERROR = "ERR_LOAD_TIMEOUT";
|
|
31
|
-
const DEFAULT_NETWORK_STATE = "networkIdle";
|
|
32
31
|
const NETWORK_STATES = ["InteractiveTime", "networkIdle", "networkAlmostIdle", "load", "DOMContentLoaded"];
|
|
33
32
|
const MINIMIZED_WINDOW_STATE = "minimized";
|
|
34
33
|
const SINGLE_FILE_WORLD_NAME = "singlefile";
|
|
35
34
|
const EMPTY_PAGE_URL = "about:blank";
|
|
36
35
|
|
|
37
|
-
export { initialize, getPageData,
|
|
36
|
+
export { initialize, getPageData, closeBrowser };
|
|
38
37
|
|
|
39
|
-
async function initialize(
|
|
38
|
+
async function initialize(singleFileOptions) {
|
|
40
39
|
if (options.browserRemoteDebuggingURL) {
|
|
41
|
-
|
|
40
|
+
options.apiUrl = singleFileOptions.browserRemoteDebuggingURL;
|
|
42
41
|
} else {
|
|
43
|
-
await launchBrowser(getBrowserOptions(
|
|
42
|
+
options.apiUrl = "http://localhost:" + (await launchBrowser(getBrowserOptions(singleFileOptions)));
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
|
|
@@ -136,11 +135,6 @@ async function getPageData(options) {
|
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
async function hasPageTargets() {
|
|
140
|
-
const targets = await CDP.getTargets();
|
|
141
|
-
return targets.filter(target => target.type === "page").length > 0;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
138
|
async function loadPage({ Page, Runtime }, options) {
|
|
145
139
|
await Runtime.enable();
|
|
146
140
|
await Page.enable();
|
|
@@ -197,7 +191,7 @@ async function getTopFrameContextId({ Page, Runtime }, options) {
|
|
|
197
191
|
|
|
198
192
|
function onLifecycleEvent({ params }) {
|
|
199
193
|
const { frameId, name } = params;
|
|
200
|
-
if (frameId === topFrameId &&
|
|
194
|
+
if (frameId === topFrameId && name === options.browserWaitUntil) {
|
|
201
195
|
removeListeners();
|
|
202
196
|
resolve();
|
|
203
197
|
}
|
package/lib/constants.js
CHANGED
|
@@ -35,7 +35,6 @@ const BROWSER_ARGS = [
|
|
|
35
35
|
"--no-default-browser-check",
|
|
36
36
|
"--disable-default-apps",
|
|
37
37
|
"--disable-dev-shm-usage",
|
|
38
|
-
"--disable-extensions",
|
|
39
38
|
"--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades,PaintHolding",
|
|
40
39
|
"--disable-hang-monitor",
|
|
41
40
|
"--disable-ipc-flooding-protection",
|
|
@@ -52,7 +51,6 @@ const BROWSER_ARGS = [
|
|
|
52
51
|
"--enable-use-zoom-for-dsf=false",
|
|
53
52
|
"--no-sandbox",
|
|
54
53
|
"--no-startup-window",
|
|
55
|
-
"--remote-debugging-port=9222",
|
|
56
54
|
"--bwsi"
|
|
57
55
|
];
|
|
58
56
|
const BROWSER_PATHS = {
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.31";
|
package/package.json
CHANGED
package/single-file-cli-api.js
CHANGED
|
@@ -151,7 +151,7 @@ async function finish(options) {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
if (!options.browserDebug && !options.browserRemoteDebuggingURL
|
|
154
|
+
if (!options.browserDebug && !options.browserRemoteDebuggingURL) {
|
|
155
155
|
return backend.closeBrowser();
|
|
156
156
|
}
|
|
157
157
|
}
|
package/single-file-launcher.js
CHANGED
|
@@ -28,8 +28,16 @@ import options from "./options.js";
|
|
|
28
28
|
|
|
29
29
|
const { readTextFile, exit, addSignalListener } = Deno;
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
addSignalListener("
|
|
31
|
+
try {
|
|
32
|
+
addSignalListener("SIGTERM", closeBrowserAndExit);
|
|
33
|
+
} catch (_error) {
|
|
34
|
+
// ignored
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
addSignalListener("SIGINT", closeBrowserAndExit);
|
|
38
|
+
} catch (_error) {
|
|
39
|
+
// ignored
|
|
40
|
+
}
|
|
33
41
|
|
|
34
42
|
export { run };
|
|
35
43
|
|