single-file-cli 2.0.20 → 2.0.22

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 CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.0.20",
3
+ "version": "2.0.22",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
7
7
  ".": "./single-file-cli-api.js"
8
8
  },
9
9
  "imports": {
10
- "simple-cdp": "jsr:@simple-cdp/simple-cdp@^1.8.2",
10
+ "simple-cdp": "jsr:@simple-cdp/simple-cdp@^1.8.5",
11
11
  "path": "jsr:@std/path@^0.220.1"
12
12
  }
13
13
  }
package/deno.lock CHANGED
@@ -2,15 +2,15 @@
2
2
  "version": "3",
3
3
  "packages": {
4
4
  "specifiers": {
5
- "jsr:@simple-cdp/simple-cdp@^1.8.2": "jsr:@simple-cdp/simple-cdp@1.8.2",
5
+ "jsr:@simple-cdp/simple-cdp@^1.8.5": "jsr:@simple-cdp/simple-cdp@1.8.5",
6
6
  "jsr:@std/assert@^0.220.1": "jsr:@std/assert@0.220.1",
7
7
  "jsr:@std/path@^0.220.1": "jsr:@std/path@0.220.1",
8
- "npm:simple-cdp@^1.8.2": "npm:simple-cdp@1.8.2",
8
+ "npm:simple-cdp@^1.8.5": "npm:simple-cdp@1.8.5",
9
9
  "npm:ws@^8.16.0": "npm:ws@8.16.0"
10
10
  },
11
11
  "jsr": {
12
- "@simple-cdp/simple-cdp@1.8.2": {
13
- "integrity": "171f82ef24c464c83f0ffc1148096a04fcd8256c6bb6b5454640614c53689165"
12
+ "@simple-cdp/simple-cdp@1.8.5": {
13
+ "integrity": "7386ca561cd6293bb3115eadf14b8c98d1c41c35a69c79774ea70e5101159413"
14
14
  },
15
15
  "@std/assert@0.220.1": {
16
16
  "integrity": "88710d54f3afdd7a5761e7805abba1f56cd14e4b212feffeb3e73a9f77482425"
@@ -23,8 +23,8 @@
23
23
  }
24
24
  },
25
25
  "npm": {
26
- "simple-cdp@1.8.2": {
27
- "integrity": "sha512-Ts4RpMMuJjdp+mLB2OJeJSUyTJZw3tUDc7ZWKytK6/4zSegwzKJEIqKv0Z2UgX0DPvma0eYg10MfaceM6CYQfA==",
26
+ "simple-cdp@1.8.5": {
27
+ "integrity": "sha512-bpXoeCk0mwFrr+8C8vVkhCug5h4HO49GI+MZdnyLQcFVKzTlokrimTjEoc69X2Y2n7mtjzDHTriq6B/kgUeUcA==",
28
28
  "dependencies": {}
29
29
  },
30
30
  "ws@8.16.0": {
@@ -36,12 +36,12 @@
36
36
  "remote": {},
37
37
  "workspace": {
38
38
  "dependencies": [
39
- "jsr:@simple-cdp/simple-cdp@^1.8.2",
39
+ "jsr:@simple-cdp/simple-cdp@^1.8.5",
40
40
  "jsr:@std/path@^0.220.1"
41
41
  ],
42
42
  "packageJson": {
43
43
  "dependencies": [
44
- "npm:simple-cdp@^1.8.2",
44
+ "npm:simple-cdp@^1.8.5",
45
45
  "npm:ws@^8.16.0"
46
46
  ]
47
47
  }
package/lib/browser.js CHANGED
@@ -66,13 +66,7 @@ async function launchBrowser(options = {}, indexPath = 0) {
66
66
  if (indexPath + 1 < BROWSER_PATHS[build.os].length) {
67
67
  await launchBrowser(options, indexPath + 1);
68
68
  } else {
69
- let message = "Chromium executable not found. ";
70
- if (options.executablePath) {
71
- message += "Make sure --browser-executable-path is correct.";
72
- } else {
73
- message += "Set the path using the --browser-executable-path option.";
74
- }
75
- throw new Error(message);
69
+ throw error;
76
70
  }
77
71
  } else {
78
72
  throw error;
package/lib/cdp-client.js CHANGED
@@ -37,13 +37,17 @@ const EMPTY_PAGE_URL = "about:blank";
37
37
  export { initialize, getPageData, closeBrowser };
38
38
 
39
39
  async function initialize(options) {
40
- await launchBrowser(getBrowserOptions(options));
40
+ if (!options.browserRemoteDebuggingURL) {
41
+ await launchBrowser(getBrowserOptions(options));
42
+ } else {
43
+ CDP.remoteDebuggingUrl = options.browserRemoteDebuggingURL;
44
+ }
41
45
  }
42
46
 
43
47
  async function getPageData(options) {
44
48
  let targetInfo;
45
49
  try {
46
- const targetInfo = await CDP.createTarget(EMPTY_PAGE_URL);
50
+ targetInfo = await CDP.createTarget(EMPTY_PAGE_URL);
47
51
  const { Browser, Security, Page, Emulation, Fetch, Network, Runtime, Debugger } = new CDP(targetInfo);
48
52
  if (options.browserStartMinimized) {
49
53
  const { windowId, bounds } = await Browser.getWindowForTarget({ targetId: targetInfo.targetId });
@@ -60,7 +64,7 @@ async function getPageData(options) {
60
64
  if (options.browserMobileEmulation) {
61
65
  await Emulation.setDeviceMetricsOverride({ mobile: true });
62
66
  }
63
- if (options.httpProxyServer && options.httpProxyUsername) {
67
+ if (options.httpProxyUsername) {
64
68
  await Fetch.enable({ handleAuthRequests: true });
65
69
  Fetch.addEventListener("authRequired", ({ params }) => Fetch.continueWithAuth({
66
70
  requestId: params.requestId,
@@ -127,7 +131,7 @@ async function getPageData(options) {
127
131
  throw error;
128
132
  } finally {
129
133
  if (targetInfo && !options.browserDebug) {
130
- await CDP.closeTarget(targetInfo.targetId);
134
+ await CDP.closeTarget(targetInfo.id);
131
135
  }
132
136
  }
133
137
  }
@@ -169,6 +173,7 @@ function getTopFrameContextId({ Page, Runtime }, options) {
169
173
  frameId = frame.id;
170
174
  if (navigationAbortController) {
171
175
  navigationAbortController.abort();
176
+ contextIds.length = 0;
172
177
  }
173
178
  navigationAbortController = new AbortController();
174
179
  await onTopFrameNavigated(navigationAbortController.signal);
@@ -214,20 +219,20 @@ function getTopFrameContextId({ Page, Runtime }, options) {
214
219
  contextIds.splice(index, 1);
215
220
  }
216
221
  }
222
+ });
217
223
 
218
- async function testExecutionContext(contextId) {
219
- try {
220
- const { result } = await Runtime.evaluate({
221
- expression: "singlefile !== undefined",
222
- contextId
223
- });
224
- return result.value === true;
225
- } catch (error) {
226
- // ignored
227
- }
228
- return false;
224
+ async function testExecutionContext(contextId) {
225
+ try {
226
+ const { result } = await Runtime.evaluate({
227
+ expression: "singlefile !== undefined",
228
+ contextId
229
+ });
230
+ return result.value === true;
231
+ } catch (error) {
232
+ // ignored
229
233
  }
230
- });
234
+ return false;
235
+ }
231
236
  }
232
237
 
233
238
  function waitForLoadTimeout(abortSignal, maxDelay) {
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "2.0.20";
1
+ export const version = "2.0.22";
package/options.js CHANGED
@@ -60,6 +60,7 @@ const OPTIONS_INFO = {
60
60
  "browser-cookie": { description: "Ordered list of cookie parameters separated by a comma (name,value,domain,path,expires,httpOnly,secure,sameSite,url)", type: "string[]" },
61
61
  "browser-cookies-file": { description: "Path of the cookies file formatted as a JSON file or a Netscape text file", type: "string" },
62
62
  "browser-ignore-insecure-certs": { description: "Ignore HTTPs errors", type: "boolean" },
63
+ "browser-remote-debugging-URL": { description: "Remote debugging URL", type: "string" },
63
64
  "compress-content": { description: "Compress the output file into a ZIP file", type: "boolean" },
64
65
  "compress-CSS": { description: "Compress CSS stylesheets", type: "boolean" },
65
66
  "compress-HTML": { description: "Compress HTML content", type: "boolean", defaultValue: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.20",
3
+ "version": "2.0.22",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -13,7 +13,7 @@
13
13
  "single-file": "./single-file-node.js"
14
14
  },
15
15
  "dependencies": {
16
- "simple-cdp": "^1.8.2",
16
+ "simple-cdp": "^1.8.5",
17
17
  "ws": "^8.16.0"
18
18
  }
19
19
  }
@@ -76,7 +76,7 @@ const DEFAULT_OPTIONS = {
76
76
  const STATE_PROCESSING = "processing";
77
77
  const STATE_PROCESSED = "processed";
78
78
 
79
- const { readTextFile, writeTextFile, writeFile, stdout, mkdir, stat } = Deno;
79
+ const { readTextFile, writeTextFile, writeFile, stdout, mkdir, stat, errors } = Deno;
80
80
  let tasks = [], maxParallelWorkers, sessionFilename;
81
81
 
82
82
  export { DEFAULT_OPTIONS, VALID_URL_TEST, initialize };
@@ -84,7 +84,21 @@ export { DEFAULT_OPTIONS, VALID_URL_TEST, initialize };
84
84
  async function initialize(options) {
85
85
  options = Object.assign({}, DEFAULT_OPTIONS, options);
86
86
  maxParallelWorkers = options.maxParallelWorkers || 8;
87
- await backend.initialize(options);
87
+ try {
88
+ await backend.initialize(options);
89
+ } catch (error) {
90
+ if (error instanceof errors.NotFound) {
91
+ let message = "Chromium executable not found. ";
92
+ if (options.browserExecutablePath) {
93
+ message += "Make sure --browser-executable-path is correct.";
94
+ } else {
95
+ message += "Set the path using the --browser-executable-path option.";
96
+ }
97
+ throw new Error(message);
98
+ } else {
99
+ throw error;
100
+ }
101
+ }
88
102
  if (options.crawlSyncSession || options.crawlLoadSession) {
89
103
  try {
90
104
  tasks = JSON.parse(await readTextFile(options.crawlSyncSession || options.crawlLoadSession));