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 CHANGED
@@ -6,7 +6,7 @@ WORKDIR /usr/src/app/node_modules/single-file-cli
6
6
 
7
7
  ENTRYPOINT [ \
8
8
  "node", \
9
- "./single-file", \
9
+ "./single-file-node.js", \
10
10
  "--browser-executable-path", "/usr/bin/chromium-browser", \
11
11
  "--output-directory", "./../../out/", \
12
12
  "--dump-content" ]
package/build.sh CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/bin/sh
2
2
 
3
- deno vendor "npm:single-file-core@1.3.28"
3
+ deno vendor "npm:single-file-core@1.4.0"
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.33",
3
+ "version": "2.0.35",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
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") || args.includes("--auto-open-devtools-for-tabs")) {
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: `singlefile.getPageData(${JSON.stringify(options)})`,
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();