single-file-cli 2.0.76 → 2.0.77
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/build.sh +1 -1
- package/deno.json +1 -1
- package/lib/browser.js +0 -3
- package/lib/cdp-client.js +88 -22
- package/lib/single-file-bundle.js +1 -1
- package/lib/single-file-script.js +59 -28
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/single-file-cli-api.js +1 -1
package/build.sh
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
mv package.json package.json.tmp
|
|
4
4
|
mv deno.json deno.json.tmp
|
|
5
5
|
mv deno.lock deno.lock.tmp
|
|
6
|
-
deno install --vendor --quiet "npm:single-file-core@1.5.
|
|
6
|
+
deno install --vendor --quiet "npm:single-file-core@1.5.57"
|
|
7
7
|
mv package.json.tmp package.json
|
|
8
8
|
mv deno.json.tmp deno.json
|
|
9
9
|
mv deno.lock.tmp deno.lock
|
package/deno.json
CHANGED
package/lib/browser.js
CHANGED
|
@@ -48,9 +48,6 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
48
48
|
if (options.debug) {
|
|
49
49
|
args.push("--auto-open-devtools-for-tabs");
|
|
50
50
|
}
|
|
51
|
-
if (options.disableWebSecurity) {
|
|
52
|
-
args.push("--disable-web-security");
|
|
53
|
-
}
|
|
54
51
|
if (options.width && options.height) {
|
|
55
52
|
args.push("--window-size=" + options.width + "," + options.height);
|
|
56
53
|
}
|
package/lib/cdp-client.js
CHANGED
|
@@ -21,10 +21,16 @@
|
|
|
21
21
|
* Source.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
/* global setTimeout, clearTimeout, URL, fetch, AbortController, window, top, singlefile */
|
|
24
|
+
/* global setTimeout, clearTimeout, URL, fetch, AbortController, window, top, singlefile, btoa, Headers, Deno */
|
|
25
25
|
|
|
26
26
|
import { launchBrowser, closeBrowser } from "./browser.js";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
FETCH_FUNCTION_NAME,
|
|
29
|
+
RESOLVE_FETCH_FUNCTION_NAME,
|
|
30
|
+
REJECT_FETCH_FUNCTION_NAME,
|
|
31
|
+
getScriptSource,
|
|
32
|
+
getHookScriptSource
|
|
33
|
+
} from "./single-file-script.js";
|
|
28
34
|
import { CDP, options } from "simple-cdp";
|
|
29
35
|
|
|
30
36
|
const LOAD_TIMEOUT_ERROR = "ERR_LOAD_TIMEOUT";
|
|
@@ -42,6 +48,41 @@ const REDIRECT_STATUS_CODES = [301, 302, 303, 307, 308];
|
|
|
42
48
|
|
|
43
49
|
export { initialize, getPageData, closeBrowser };
|
|
44
50
|
|
|
51
|
+
async function fetchWithFileSupport(url, fetchOptions = {}) {
|
|
52
|
+
if (url.startsWith("file://")) {
|
|
53
|
+
const filePath = decodeURIComponent(url.replace(/^file:\/\//, ""));
|
|
54
|
+
let fileData;
|
|
55
|
+
if (typeof Deno !== "undefined") {
|
|
56
|
+
const response = await fetch(url, fetchOptions);
|
|
57
|
+
return response;
|
|
58
|
+
} else {
|
|
59
|
+
const { readFile } = await import("node:fs/promises");
|
|
60
|
+
try {
|
|
61
|
+
fileData = await readFile(filePath);
|
|
62
|
+
return {
|
|
63
|
+
status: 200,
|
|
64
|
+
headers: new Headers({
|
|
65
|
+
"content-type": "application/octet-stream",
|
|
66
|
+
"content-length": fileData.length.toString()
|
|
67
|
+
}),
|
|
68
|
+
arrayBuffer: async () => fileData.buffer
|
|
69
|
+
};
|
|
70
|
+
} catch {
|
|
71
|
+
return {
|
|
72
|
+
status: 404,
|
|
73
|
+
headers: new Headers({
|
|
74
|
+
"content-type": "text/plain",
|
|
75
|
+
"content-length": "0"
|
|
76
|
+
}),
|
|
77
|
+
arrayBuffer: async () => new ArrayBuffer(0)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
return await fetch(url, fetchOptions);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
45
86
|
async function initialize(singleFileOptions) {
|
|
46
87
|
if (singleFileOptions.browserServer) {
|
|
47
88
|
options.apiUrl = singleFileOptions.browserServer;
|
|
@@ -85,12 +126,6 @@ async function getPageData(options) {
|
|
|
85
126
|
}
|
|
86
127
|
await Security.setIgnoreCertificateErrors({ ignore: true });
|
|
87
128
|
}
|
|
88
|
-
if (options.browserByPassCSP === undefined || options.browserByPassCSP) {
|
|
89
|
-
if (options.debugMessagesFile) {
|
|
90
|
-
debugMessages.push([Date.now(), ["Bypassing CSP"]]);
|
|
91
|
-
}
|
|
92
|
-
await Page.setBypassCSP({ enabled: true });
|
|
93
|
-
}
|
|
94
129
|
if (options.browserMobileEmulation || options.browserDeviceWidth || options.browserDeviceHeight || options.browserDeviceScaleFactor || options.platform || options.acceptLanguage) {
|
|
95
130
|
if (options.browserMobileEmulation || options.browserDeviceWidth || options.browserDeviceHeight || options.browserDeviceScaleFactor) {
|
|
96
131
|
let browserDeviceWidth;
|
|
@@ -295,6 +330,41 @@ async function getPageData(options) {
|
|
|
295
330
|
}
|
|
296
331
|
});
|
|
297
332
|
}
|
|
333
|
+
await Runtime.addBinding({ name: FETCH_FUNCTION_NAME, executionContextId: contextId });
|
|
334
|
+
Runtime.addEventListener("bindingCalled", async ({ params }) => {
|
|
335
|
+
if (params.name === FETCH_FUNCTION_NAME) {
|
|
336
|
+
let { payload } = params;
|
|
337
|
+
payload = JSON.parse(payload);
|
|
338
|
+
const { requestId, url, options: fetchOptions } = payload;
|
|
339
|
+
if (options.debugMessagesFile) {
|
|
340
|
+
debugMessages.push([Date.now(), ["Fetching URL", url]]);
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
const response = await fetchWithFileSupport(url, fetchOptions);
|
|
344
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
345
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
346
|
+
const data = btoa(String.fromCharCode.apply(null, uint8Array));
|
|
347
|
+
const result = {
|
|
348
|
+
status: response.status,
|
|
349
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
350
|
+
data
|
|
351
|
+
};
|
|
352
|
+
await Runtime.evaluate({
|
|
353
|
+
expression: `globalThis.${RESOLVE_FETCH_FUNCTION_NAME}(${JSON.stringify(requestId)}, ${JSON.stringify(result)})`,
|
|
354
|
+
contextId
|
|
355
|
+
});
|
|
356
|
+
} catch (error) {
|
|
357
|
+
const errorResult = {
|
|
358
|
+
error: error.message,
|
|
359
|
+
code: error.code
|
|
360
|
+
};
|
|
361
|
+
await Runtime.evaluate({
|
|
362
|
+
expression: `globalThis.${REJECT_FETCH_FUNCTION_NAME}(${JSON.stringify(requestId)}, ${JSON.stringify(errorResult)})`,
|
|
363
|
+
contextId
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
});
|
|
298
368
|
const pageDataPromise = new Promise(resolve => {
|
|
299
369
|
let pageDataResponse = "";
|
|
300
370
|
Runtime.addEventListener("bindingCalled", ({ params }) => {
|
|
@@ -597,20 +667,16 @@ function waitForTimeout(abortSignal, maxDelay, errorMessage, errorCode) {
|
|
|
597
667
|
|
|
598
668
|
async function waitForDebuggerReady({ Debugger }) {
|
|
599
669
|
await Debugger.enable();
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
Debugger.addEventListener(RESUMED_EVENT, onResumed);
|
|
670
|
+
await Debugger.pause();
|
|
671
|
+
await new Promise(resolve => {
|
|
672
|
+
const RESUMED_EVENT = "resumed";
|
|
673
|
+
Debugger.addEventListener(RESUMED_EVENT, onResumed);
|
|
605
674
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
} finally {
|
|
612
|
-
await Debugger.disable();
|
|
613
|
-
}
|
|
675
|
+
function onResumed() {
|
|
676
|
+
Debugger.removeEventListener(RESUMED_EVENT, onResumed);
|
|
677
|
+
resolve();
|
|
678
|
+
}
|
|
679
|
+
});
|
|
614
680
|
}
|
|
615
681
|
|
|
616
682
|
function getBrowserOptions(options) {
|
|
@@ -619,7 +685,7 @@ function getBrowserOptions(options) {
|
|
|
619
685
|
browserOptions.headless = options.browserHeadless;
|
|
620
686
|
browserOptions.executablePath = options.browserExecutablePath;
|
|
621
687
|
browserOptions.debug = options.browserDebug;
|
|
622
|
-
browserOptions.disableWebSecurity = options.browserDisableWebSecurity
|
|
688
|
+
browserOptions.disableWebSecurity = options.browserDisableWebSecurity;
|
|
623
689
|
browserOptions.width = options.browserWidth;
|
|
624
690
|
browserOptions.height = options.browserHeight;
|
|
625
691
|
browserOptions.userAgent = options.userAgent;
|