single-file-cli 2.0.67 → 2.0.69

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/README.MD CHANGED
@@ -65,7 +65,7 @@ Make sure Chrome or a Chromium-based browser is installed in the default folder.
65
65
 
66
66
  - There are 3 ways to download the code of SingleFile, choose the one you prefer:
67
67
 
68
- - Install with `npm` (`npm` is installed with Node.js) and run with `npx`
68
+ - Install with `npm` and run `single-file` via `npx` (`npm` and `npx` are installed with Node.js)
69
69
 
70
70
  ```sh
71
71
  npm install "single-file-cli"
package/build.sh CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- deno vendor "npm:single-file-core@1.5.35"
3
+ deno vendor "npm:single-file-core@1.5.36"
4
4
 
5
5
  echo "
6
6
  import { build } from 'npm:esbuild';
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.0.67",
3
+ "version": "2.0.69",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
package/lib/browser.js CHANGED
@@ -92,7 +92,7 @@ async function launchBrowser(options = {}, indexPath = 0) {
92
92
  async function getDebugPort(port = getRandomDebugPort(), usedPorts = []) {
93
93
  try {
94
94
  await fetch("http://localhost:" + port + "/json/version");
95
- } catch (error) {
95
+ } catch {
96
96
  return port;
97
97
  }
98
98
  if (usedPorts.length < DEBUG_PORT_RANGE) {
@@ -121,7 +121,7 @@ async function closeBrowser() {
121
121
  try {
122
122
  await remove(profilePath, { recursive: true });
123
123
  profilePath = undefined;
124
- } catch (error) {
124
+ } catch {
125
125
  console.log("Warning: failed to remove profile directory: " + profilePath); // eslint-disable-line no-console
126
126
  }
127
127
  }
package/lib/cdp-client.js CHANGED
@@ -159,7 +159,7 @@ async function getPageData(options) {
159
159
  }
160
160
  try {
161
161
  await Fetch.continueRequest({ requestId });
162
- } catch (error) {
162
+ } catch {
163
163
  // ignored
164
164
  }
165
165
  });
@@ -177,6 +177,7 @@ async function getPageData(options) {
177
177
  if (options.browserCookies && options.browserCookies.length) {
178
178
  await Network.setCookies({ cookies: options.browserCookies });
179
179
  }
180
+ await Browser.setDownloadBehavior({ behavior: "deny" });
180
181
  await Page.addScriptToEvaluateOnNewDocument({
181
182
  source: getHookScriptSource(),
182
183
  runImmediately: true
@@ -200,14 +201,14 @@ async function getPageData(options) {
200
201
  if (options.embedScreenshotOptions) {
201
202
  try {
202
203
  screenshotOptions = JSON.parse(options.embedScreenshotOptions);
203
- } catch (error) {
204
+ } catch {
204
205
  // ignored
205
206
  }
206
207
  }
207
208
  screenshotOptions.format = "png";
208
209
  const { data } = await Page.captureScreenshot(screenshotOptions);
209
210
  await Runtime.evaluate({ expression: `globalThis.${SET_SCREENSHOT_FUNCTION_NAME}(${JSON.stringify(data)})`, contextId });
210
- } catch (error) {
211
+ } catch {
211
212
  await Runtime.evaluate({ expression: `globalThis.${SET_SCREENSHOT_FUNCTION_NAME}(${JSON.stringify("")})`, contextId });
212
213
  }
213
214
  }
@@ -221,14 +222,14 @@ async function getPageData(options) {
221
222
  if (options.embedPdfOptions) {
222
223
  try {
223
224
  pdfOptions = JSON.parse(options.embedPdfOptions);
224
- } catch (error) {
225
+ } catch {
225
226
  // ignored
226
227
  }
227
228
  }
228
229
  try {
229
230
  const { data } = await Page.printToPDF(pdfOptions);
230
231
  await Runtime.evaluate({ expression: `globalThis.${SET_PDF_FUNCTION_NAME}(${JSON.stringify(data)})`, contextId });
231
- } catch (error) {
232
+ } catch {
232
233
  await Runtime.evaluate({ expression: `globalThis.${SET_PDF_FUNCTION_NAME}(${JSON.stringify("")})`, contextId });
233
234
  }
234
235
  }
@@ -236,7 +237,7 @@ async function getPageData(options) {
236
237
  }
237
238
  const pageDataPromise = new Promise(resolve => {
238
239
  let pageDataResponse = "";
239
- Runtime.addEventListener("bindingCalled", async ({ params }) => {
240
+ Runtime.addEventListener("bindingCalled", ({ params }) => {
240
241
  if (params.name === SET_PAGE_DATA_FUNCTION_NAME) {
241
242
  const { payload } = params;
242
243
  if (payload.length) {
@@ -276,13 +277,19 @@ async function getPageData(options) {
276
277
  const browserWaitUntil = NETWORK_STATES[(NETWORK_STATES.indexOf(options.browserWaitUntil) + 1)];
277
278
  if (browserWaitUntil) {
278
279
  options.browserWaitUntil = browserWaitUntil;
280
+ await closeTarget();
279
281
  return await getPageData(options);
280
282
  }
281
283
  }
282
284
  throw error;
283
285
  } finally {
286
+ await closeTarget();
287
+ }
288
+
289
+ async function closeTarget() {
284
290
  if (targetInfo && !options.browserDebug) {
285
291
  await CDP.closeTarget(targetInfo.id);
292
+ targetInfo = null;
286
293
  }
287
294
  }
288
295
  }
@@ -374,6 +381,7 @@ async function getTopFrameContextId({ Page, Runtime }, options) {
374
381
  }
375
382
 
376
383
  async function waitForPageReady({ Page }, options) {
384
+ let resolveCallbackTimeout;
377
385
  await Page.setLifecycleEventsEnabled({ enabled: true });
378
386
  try {
379
387
  await new Promise((resolve, reject) => {
@@ -384,9 +392,12 @@ async function getTopFrameContextId({ Page, Runtime }, options) {
384
392
 
385
393
  function onLifecycleEvent({ params }) {
386
394
  const { frameId, name } = params;
387
- if (frameId === topFrameId && name === options.browserWaitUntil) {
388
- removeListeners();
389
- resolve();
395
+ if (frameId === topFrameId && name === options.browserWaitUntil || (resolveCallbackTimeout && NETWORK_STATES.indexOf(name) < NETWORK_STATES.indexOf(options.browserWaitUntil))) {
396
+ clearTimeout(resolveCallbackTimeout);
397
+ setTimeout(() => {
398
+ removeListeners();
399
+ resolve();
400
+ }, options.browserWaitUntilDelay);
390
401
  }
391
402
  }
392
403
 
@@ -394,6 +405,7 @@ async function getTopFrameContextId({ Page, Runtime }, options) {
394
405
  const { frame } = params;
395
406
  if (!frame.parentId) {
396
407
  if (frame.unreachableUrl) {
408
+ clearTimeout(resolveCallbackTimeout);
397
409
  removeListeners();
398
410
  reject(new Error("Unreachable URL: " + frame.unreachableUrl));
399
411
  } else {
@@ -433,7 +445,7 @@ async function getTopFrameContextId({ Page, Runtime }, options) {
433
445
  contextId
434
446
  });
435
447
  return result.value === true;
436
- } catch (error) {
448
+ } catch {
437
449
  // ignored
438
450
  }
439
451
  return false;
@@ -21,6 +21,8 @@
21
21
  * Source.
22
22
  */
23
23
 
24
+ // deno-lint-ignore-file no-node-globals
25
+
24
26
  /* global globalThis, URL, Deno, process */
25
27
 
26
28
  import * as path from "path";
@@ -244,7 +246,7 @@ async function cwd() {
244
246
  }
245
247
  }
246
248
 
247
- async function dirname(filePath) {
249
+ function dirname(filePath) {
248
250
  return path.dirname(filePath);
249
251
  }
250
252