single-file-cli 2.0.25 → 2.0.27
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 +1 -1
- package/lib/cdp-client.js +40 -52
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/single-file-node.bat +1 -1
package/deno.json
CHANGED
package/lib/browser.js
CHANGED
|
@@ -34,7 +34,7 @@ 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
|
-
if (options.headless) {
|
|
37
|
+
if (options.headless && !options.debug) {
|
|
38
38
|
args.push("--headless");
|
|
39
39
|
} else {
|
|
40
40
|
args.push("--start-maximized");
|
package/lib/cdp-client.js
CHANGED
|
@@ -142,12 +142,11 @@ async function hasPageTargets() {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
async function loadPage({ Page, Runtime }, options) {
|
|
145
|
-
let loadTimeoutAbortController, loadTimeoutAbortSignal;
|
|
146
145
|
await Runtime.enable();
|
|
147
146
|
await Page.enable();
|
|
147
|
+
const loadTimeoutAbortController = new AbortController();
|
|
148
|
+
const loadTimeoutAbortSignal = loadTimeoutAbortController.signal;
|
|
148
149
|
try {
|
|
149
|
-
loadTimeoutAbortController = new AbortController();
|
|
150
|
-
loadTimeoutAbortSignal = loadTimeoutAbortController.signal;
|
|
151
150
|
const [contextId] = await Promise.race([
|
|
152
151
|
Promise.all([getTopFrameContextId({ Page, Runtime }, options), Page.navigate({ url: options.url })]),
|
|
153
152
|
waitForLoadTimeout(loadTimeoutAbortSignal, options.browserLoadMaxTime)
|
|
@@ -166,52 +165,50 @@ function getTopFrameContextId({ Page, Runtime }, options) {
|
|
|
166
165
|
return new Promise((resolve, reject) => {
|
|
167
166
|
const FRAME_NAVIGATED_EVENT = "frameNavigated";
|
|
168
167
|
const CONTEXT_CREATED_EVENT = "executionContextCreated";
|
|
169
|
-
const CONTEXT_DESTROYED_EVENT = "executionContextDestroyed";
|
|
170
168
|
const contextIds = [];
|
|
171
|
-
let frameId
|
|
169
|
+
let frameId;
|
|
172
170
|
Page.addEventListener(FRAME_NAVIGATED_EVENT, onFrameNavigated);
|
|
173
171
|
Runtime.addEventListener(CONTEXT_CREATED_EVENT, onExecutionContextCreated);
|
|
174
|
-
Runtime.addEventListener(CONTEXT_DESTROYED_EVENT, onExecutionContextDestroyed);
|
|
175
172
|
|
|
176
173
|
async function onFrameNavigated({ params }) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
174
|
+
try {
|
|
175
|
+
const { frame } = params;
|
|
176
|
+
if (!frame.parentId) {
|
|
177
|
+
if (frame.unreachableUrl) {
|
|
178
|
+
reject(new Error("Unreachable URL: " + frame.unreachableUrl));
|
|
179
|
+
} else {
|
|
180
|
+
frameId = frame.id;
|
|
181
|
+
await onTopFrameNavigated();
|
|
182
|
+
}
|
|
185
183
|
}
|
|
186
|
-
|
|
187
|
-
|
|
184
|
+
} finally {
|
|
185
|
+
Page.removeEventListener(FRAME_NAVIGATED_EVENT, onFrameNavigated);
|
|
186
|
+
Runtime.removeEventListener(CONTEXT_CREATED_EVENT, onExecutionContextCreated);
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
189
|
|
|
191
|
-
async function onTopFrameNavigated(
|
|
192
|
-
await waitForPageReady({ Page }, frameId, options
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (contextId === undefined) {
|
|
209
|
-
reject(new Error("Execution context not found"));
|
|
210
|
-
} else {
|
|
211
|
-
resolve(contextId);
|
|
190
|
+
async function onTopFrameNavigated() {
|
|
191
|
+
await waitForPageReady({ Page }, frameId, options);
|
|
192
|
+
const contextId = await getContextId();
|
|
193
|
+
if (contextId === undefined) {
|
|
194
|
+
reject(new Error("Execution context not found"));
|
|
195
|
+
} else {
|
|
196
|
+
resolve(contextId);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function getContextId() {
|
|
201
|
+
let contextId;
|
|
202
|
+
if (contextIds.length) {
|
|
203
|
+
let contextIdIndex = 0;
|
|
204
|
+
do {
|
|
205
|
+
if (await testExecutionContext(contextIds[contextIdIndex])) {
|
|
206
|
+
contextId = contextIds[contextIdIndex];
|
|
212
207
|
}
|
|
213
|
-
|
|
208
|
+
contextIdIndex++;
|
|
209
|
+
} while (contextId === undefined && contextIdIndex < contextIds.length);
|
|
214
210
|
}
|
|
211
|
+
return contextId;
|
|
215
212
|
}
|
|
216
213
|
|
|
217
214
|
function onExecutionContextCreated({ params }) {
|
|
@@ -221,14 +218,6 @@ function getTopFrameContextId({ Page, Runtime }, options) {
|
|
|
221
218
|
contextIds.push(context.id);
|
|
222
219
|
}
|
|
223
220
|
}
|
|
224
|
-
|
|
225
|
-
function onExecutionContextDestroyed({ params }) {
|
|
226
|
-
const { executionContextId } = params;
|
|
227
|
-
const index = contextIds.indexOf(executionContextId);
|
|
228
|
-
if (index > -1) {
|
|
229
|
-
contextIds.splice(index, 1);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
221
|
});
|
|
233
222
|
|
|
234
223
|
async function testExecutionContext(contextId) {
|
|
@@ -250,6 +239,7 @@ function waitForLoadTimeout(abortSignal, maxDelay) {
|
|
|
250
239
|
const ABORT_EVENT = "abort";
|
|
251
240
|
abortSignal.addEventListener(ABORT_EVENT, onAbort);
|
|
252
241
|
const timeoutId = setTimeout(() => {
|
|
242
|
+
abortSignal.removeEventListener(ABORT_EVENT, onAbort);
|
|
253
243
|
const error = new Error("Load timeout");
|
|
254
244
|
error.code = LOAD_TIMEOUT_ERROR;
|
|
255
245
|
reject(error);
|
|
@@ -263,7 +253,7 @@ function waitForLoadTimeout(abortSignal, maxDelay) {
|
|
|
263
253
|
});
|
|
264
254
|
}
|
|
265
255
|
|
|
266
|
-
async function waitForPageReady({ Page }, topFrameId, options
|
|
256
|
+
async function waitForPageReady({ Page }, topFrameId, options) {
|
|
267
257
|
await Page.setLifecycleEventsEnabled({ enabled: true });
|
|
268
258
|
try {
|
|
269
259
|
await new Promise(resolve => {
|
|
@@ -272,16 +262,14 @@ async function waitForPageReady({ Page }, topFrameId, options, navigationSignal)
|
|
|
272
262
|
|
|
273
263
|
function onLifecycleEvent({ params }) {
|
|
274
264
|
const { name, frameId } = params;
|
|
275
|
-
if (frameId === topFrameId && (name === options.browserWaitUntil || name === DEFAULT_NETWORK_STATE
|
|
265
|
+
if (frameId === topFrameId && (name === options.browserWaitUntil || name === DEFAULT_NETWORK_STATE)) {
|
|
276
266
|
Page.removeEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
|
|
277
267
|
resolve();
|
|
278
268
|
}
|
|
279
269
|
}
|
|
280
270
|
});
|
|
281
271
|
} finally {
|
|
282
|
-
|
|
283
|
-
await Page.setLifecycleEventsEnabled({ enabled: false });
|
|
284
|
-
}
|
|
272
|
+
await Page.setLifecycleEventsEnabled({ enabled: false });
|
|
285
273
|
}
|
|
286
274
|
}
|
|
287
275
|
|
|
@@ -306,7 +294,7 @@ async function waitForDebuggerReady({ Debugger }) {
|
|
|
306
294
|
function getBrowserOptions(options) {
|
|
307
295
|
const browserOptions = {};
|
|
308
296
|
browserOptions.args = options.browserArgs;
|
|
309
|
-
browserOptions.headless = options.browserHeadless
|
|
297
|
+
browserOptions.headless = options.browserHeadless;
|
|
310
298
|
browserOptions.executablePath = options.browserExecutablePath;
|
|
311
299
|
browserOptions.debug = options.browserDebug;
|
|
312
300
|
browserOptions.disableWebSecurity = options.browserDisableWebSecurity === undefined || options.browserDisableWebSecurity;
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.27";
|
package/package.json
CHANGED
package/single-file-node.bat
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
@echo off
|
|
2
|
-
node "%~dp0\single-file" %*
|
|
2
|
+
node "%~dp0\single-file-node.js" %*
|