single-file-cli 2.0.33 → 2.0.35
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/Dockerfile +1 -1
- package/build.sh +1 -1
- package/deno.json +1 -1
- package/lib/browser.js +4 -1
- package/lib/cdp-client.js +36 -1
- package/lib/single-file-bundle.js +1 -1
- package/lib/version.js +1 -1
- package/options.js +3 -2
- package/package.json +1 -1
- package/single-file-cli-api.js +0 -19
- package/single-file-launcher.js +3 -3
package/Dockerfile
CHANGED
package/build.sh
CHANGED
package/deno.json
CHANGED
package/lib/browser.js
CHANGED
|
@@ -64,7 +64,10 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
64
64
|
args = args.filter(arg => !argNames.includes(arg.split("=")[0]));
|
|
65
65
|
args.push(...options.args);
|
|
66
66
|
}
|
|
67
|
-
if (args.includes("--headless=new") ||
|
|
67
|
+
if (args.includes("--headless=new") ||
|
|
68
|
+
args.includes("--auto-open-devtools-for-tabs") ||
|
|
69
|
+
args.includes("--start-maximized") ||
|
|
70
|
+
!args.includes("--headless")) {
|
|
68
71
|
args.push("--disable-site-isolation-trials");
|
|
69
72
|
}
|
|
70
73
|
const command = new Command(executablePath, { args, stdout: PIPED_STD_CONFIG, stderr: PIPED_STD_CONFIG });
|
package/lib/cdp-client.js
CHANGED
|
@@ -32,6 +32,8 @@ const NETWORK_STATES = ["InteractiveTime", "networkIdle", "networkAlmostIdle", "
|
|
|
32
32
|
const MINIMIZED_WINDOW_STATE = "minimized";
|
|
33
33
|
const SINGLE_FILE_WORLD_NAME = "singlefile";
|
|
34
34
|
const EMPTY_PAGE_URL = "about:blank";
|
|
35
|
+
const CAPTURE_SCREENSHOT_FUNCTION_NAME = "captureScreenshot";
|
|
36
|
+
const SET_SCREENSHOT_FUNCTION_NAME = "setScreenshot";
|
|
35
37
|
|
|
36
38
|
export { initialize, getPageData, closeBrowser };
|
|
37
39
|
|
|
@@ -105,8 +107,16 @@ async function getPageData(options) {
|
|
|
105
107
|
if (options.browserWaitDelay) {
|
|
106
108
|
setTimeout(() => resolve, options.browserWaitDelay);
|
|
107
109
|
}
|
|
110
|
+
if (options.embedScreenshot && options.compressContent) {
|
|
111
|
+
await Runtime.addBinding({ name: CAPTURE_SCREENSHOT_FUNCTION_NAME, executionContextId: contextId });
|
|
112
|
+
Runtime.addEventListener("bindingCalled", ({ params }) => {
|
|
113
|
+
if (params.name === CAPTURE_SCREENSHOT_FUNCTION_NAME) {
|
|
114
|
+
onCaptureScreenshot({ Page, Runtime }, contextId);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
108
118
|
const { result } = await Runtime.evaluate({
|
|
109
|
-
expression: `
|
|
119
|
+
expression: `(${getPageDataScriptSource.toString()})(${JSON.stringify(options)},${JSON.stringify(SET_SCREENSHOT_FUNCTION_NAME)})`,
|
|
110
120
|
awaitPromise: true,
|
|
111
121
|
returnByValue: true,
|
|
112
122
|
contextId
|
|
@@ -135,6 +145,31 @@ async function getPageData(options) {
|
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
147
|
|
|
148
|
+
async function onCaptureScreenshot({ Page, Runtime }, contextId) {
|
|
149
|
+
const { data } = await Page.captureScreenshot({ format: "png", captureBeyondViewport: true });
|
|
150
|
+
const dataURI = "data:image/png;base64," + data;
|
|
151
|
+
const screenshotData = Array.from(new Uint8Array(await (await fetch(dataURI)).arrayBuffer()));
|
|
152
|
+
await Runtime.evaluate({
|
|
153
|
+
expression: `globalThis.${SET_SCREENSHOT_FUNCTION_NAME}(${JSON.stringify(screenshotData)})`,
|
|
154
|
+
contextId
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function getPageDataScriptSource(options, SET_SCREENSHOT_FUNCTION_NAME) {
|
|
159
|
+
if (options.embedScreenshot && options.compressContent) {
|
|
160
|
+
let screenshot = new Promise(resolve => globalThis[SET_SCREENSHOT_FUNCTION_NAME] = resolve);
|
|
161
|
+
let pendingCapture;
|
|
162
|
+
options.onprogress = async event => {
|
|
163
|
+
if (event.type == event.RESOURCES_INITIALIZING && globalThis.captureScreenshot && window == top && !pendingCapture) {
|
|
164
|
+
pendingCapture = true;
|
|
165
|
+
globalThis.captureScreenshot("");
|
|
166
|
+
options.embeddedImage = await screenshot;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return singlefile.getPageData(options);
|
|
171
|
+
}
|
|
172
|
+
|
|
138
173
|
async function loadPage({ Page, Runtime }, options) {
|
|
139
174
|
await Runtime.enable();
|
|
140
175
|
await Page.enable();
|