single-file-cli 2.0.29 → 2.0.30
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 +17 -2
- package/lib/cdp-client.js +6 -12
- package/lib/constants.js +0 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/single-file-cli-api.js +1 -1
package/deno.json
CHANGED
package/lib/browser.js
CHANGED
|
@@ -34,6 +34,8 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
34
34
|
const executablePath = options.executablePath || BROWSER_PATHS[build.os][indexPath];
|
|
35
35
|
const args = Array.from(BROWSER_ARGS);
|
|
36
36
|
profilePath = await makeTempDir();
|
|
37
|
+
const debugPort = await getDebugPort();
|
|
38
|
+
args.push("--remote-debugging-port=" + debugPort);
|
|
37
39
|
if (options.headless && !options.debug) {
|
|
38
40
|
args.push("--headless");
|
|
39
41
|
} else {
|
|
@@ -64,7 +66,7 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
64
66
|
} catch (error) {
|
|
65
67
|
if (error instanceof errors.NotFound) {
|
|
66
68
|
if (indexPath + 1 < BROWSER_PATHS[build.os].length) {
|
|
67
|
-
|
|
69
|
+
return launchBrowser(options, indexPath + 1);
|
|
68
70
|
} else {
|
|
69
71
|
throw error;
|
|
70
72
|
}
|
|
@@ -73,7 +75,20 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
child.ref();
|
|
76
|
-
return
|
|
78
|
+
return debugPort;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function getDebugPort(port = 9222) {
|
|
82
|
+
try {
|
|
83
|
+
await fetch("http://localhost:" + port + "/json/version");
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return port;
|
|
86
|
+
}
|
|
87
|
+
if (port < 9286) {
|
|
88
|
+
return getDebugPort(port + 1);
|
|
89
|
+
} else {
|
|
90
|
+
throw new Error("No available debugging port");
|
|
91
|
+
}
|
|
77
92
|
}
|
|
78
93
|
|
|
79
94
|
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
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.30";
|
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
|
}
|