single-file-cli 2.0.62 → 2.0.64

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
@@ -2,11 +2,11 @@ FROM zenika/alpine-chrome:with-node
2
2
 
3
3
  RUN npm install --omit=dev single-file-cli
4
4
 
5
- WORKDIR /usr/src/app/node_modules/single-file-cli
5
+ WORKDIR /usr/src/app
6
6
 
7
7
  ENTRYPOINT [ \
8
- "node", \
9
- "./single-file-node.js", \
8
+ "npx", \
9
+ "single-file", \
10
10
  "--browser-executable-path", "/usr/bin/chromium-browser", \
11
- "--output-directory", "./../../out/", \
11
+ "--output-directory", "./out/", \
12
12
  "--dump-content" ]
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.30"
3
+ deno vendor "npm:single-file-core@1.5.32"
4
4
 
5
5
  echo "
6
6
  import { build } from 'npm:esbuild';
package/compile.sh CHANGED
@@ -8,7 +8,7 @@ deno compile --allow-read --allow-write --allow-net --allow-env --allow-run --ex
8
8
  deno compile --allow-read --allow-write --allow-net --allow-env --allow-run --ext=js --output=./dist/single-file-x86_64-apple-darwin --target=x86_64-apple-darwin ./single-file
9
9
  deno compile --allow-read --allow-write --allow-net --allow-env --allow-run --ext=js --output=./dist/single-file-x86_64-linux --target=x86_64-unknown-linux-gnu ./single-file
10
10
  deno compile --allow-read --allow-write --allow-net --allow-env --allow-run --ext=js --output=./dist/single-file-aarch64-linux --target=aarch64-unknown-linux-gnu ./single-file
11
- deno compile --allow-read --allow-write --allow-net --allow-env --allow-run --ext=js --output=./dist/single-file.exe --target=x86_64-pc-windows-msvc ./single-file
11
+ deno compile --allow-read --allow-write --allow-net --allow-env --allow-run --ext=js --output=./dist/single-file.exe --target=x86_64-pc-windows-msvc --icon=./resources/single-file.ico ./single-file
12
12
 
13
13
  dev_id=$(security find-identity -p codesigning -v | grep "Apple Development" | awk '{print $2}')
14
14
  codesign -f -s $dev_id ./dist/single-file-aarch64-apple-darwin
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.0.62",
3
+ "version": "2.0.64",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
package/lib/cdp-client.js CHANGED
@@ -33,9 +33,9 @@ const MINIMIZED_WINDOW_STATE = "minimized";
33
33
  const SINGLE_FILE_WORLD_NAME = "singlefile";
34
34
  const EMPTY_PAGE_URL = "about:blank";
35
35
  const CAPTURE_SCREENSHOT_FUNCTION_NAME = "captureScreenshot";
36
- const CAPTURE_PDF_FUNCTION_NAME = "capturePdf";
36
+ const PRINT_TO_PDF_FUNCTION_NAME = "printToPDF";
37
37
  const SET_SCREENSHOT_FUNCTION_NAME = "setScreenshot";
38
- const SET_PDF_FUNCTION_NAME = "setPdf";
38
+ const SET_PDF_FUNCTION_NAME = "setPDF";
39
39
  const SET_PAGE_DATA_FUNCTION_NAME = "setPageData";
40
40
  const REDIRECT_STATUS_CODES = [301, 302, 303, 307, 308];
41
41
 
@@ -208,21 +208,28 @@ async function getPageData(options) {
208
208
  Runtime.addEventListener("bindingCalled", async ({ params }) => {
209
209
  if (params.name === CAPTURE_SCREENSHOT_FUNCTION_NAME) {
210
210
  try {
211
- await onCaptureScreenshot({ Page, Runtime }, contextId);
211
+ let screenshotOptions = { captureBeyondViewport: true };
212
+ if (options.embedScreenshotOptions) {
213
+ try {
214
+ screenshotOptions = JSON.parse(options.embedScreenshotOptions);
215
+ } catch (error) {
216
+ // ignored
217
+ }
218
+ }
219
+ screenshotOptions.format = "png";
220
+ const { data } = await Page.captureScreenshot(screenshotOptions);
221
+ await Runtime.evaluate({ expression: `globalThis.${SET_SCREENSHOT_FUNCTION_NAME}(${JSON.stringify(data)})`, contextId });
212
222
  } catch (error) {
213
- await Runtime.evaluate({
214
- expression: `globalThis.${SET_SCREENSHOT_FUNCTION_NAME}(${JSON.stringify([])})`,
215
- contextId
216
- });
223
+ await Runtime.evaluate({ expression: `globalThis.${SET_SCREENSHOT_FUNCTION_NAME}(${JSON.stringify("")})`, contextId });
217
224
  }
218
225
  }
219
226
  });
220
227
  }
221
228
  if (options.embedPdf) {
222
- await Runtime.addBinding({ name: CAPTURE_PDF_FUNCTION_NAME, executionContextId: contextId });
229
+ await Runtime.addBinding({ name: PRINT_TO_PDF_FUNCTION_NAME, executionContextId: contextId });
223
230
  Runtime.addEventListener("bindingCalled", async ({ params }) => {
224
- if (params.name === CAPTURE_PDF_FUNCTION_NAME) {
225
- let pdfOptions;
231
+ if (params.name === PRINT_TO_PDF_FUNCTION_NAME) {
232
+ let pdfOptions = {};
226
233
  if (options.embedPdfOptions) {
227
234
  try {
228
235
  pdfOptions = JSON.parse(options.embedPdfOptions);
@@ -231,18 +238,16 @@ async function getPageData(options) {
231
238
  }
232
239
  }
233
240
  try {
234
- await onCapturePdf({ Page, Runtime }, contextId, pdfOptions);
241
+ const { data } = await Page.printToPDF(pdfOptions);
242
+ await Runtime.evaluate({ expression: `globalThis.${SET_PDF_FUNCTION_NAME}(${JSON.stringify(data)})`, contextId });
235
243
  } catch (error) {
236
- await Runtime.evaluate({
237
- expression: `globalThis.${SET_PDF_FUNCTION_NAME}ƒƒ(${JSON.stringify([])})`,
238
- contextId
239
- });
244
+ await Runtime.evaluate({ expression: `globalThis.${SET_PDF_FUNCTION_NAME}(${JSON.stringify("")})`, contextId });
240
245
  }
241
246
  }
242
247
  });
243
248
  }
244
249
  const { result } = await Runtime.evaluate({
245
- expression: `(${getPageDataScriptSource.toString()})(${JSON.stringify(options)},${JSON.stringify([SET_SCREENSHOT_FUNCTION_NAME, SET_PDF_FUNCTION_NAME, SET_PAGE_DATA_FUNCTION_NAME])})`,
250
+ expression: `(${getPageDataScriptSource.toString()})(${JSON.stringify(options)},${JSON.stringify([SET_SCREENSHOT_FUNCTION_NAME, SET_PDF_FUNCTION_NAME, SET_PAGE_DATA_FUNCTION_NAME, CAPTURE_SCREENSHOT_FUNCTION_NAME, PRINT_TO_PDF_FUNCTION_NAME])})`,
246
251
  awaitPromise: true,
247
252
  returnByValue: true,
248
253
  contextId
@@ -270,44 +275,27 @@ async function getPageData(options) {
270
275
  }
271
276
  }
272
277
 
273
- async function onCaptureScreenshot({ Page, Runtime }, contextId) {
274
- const { data } = await Page.captureScreenshot({ format: "png", captureBeyondViewport: true });
275
- const dataURI = "data:image/png;base64," + data;
276
- const screenshotData = Array.from(new Uint8Array(await (await fetch(dataURI)).arrayBuffer()));
277
- await Runtime.evaluate({
278
- expression: `globalThis.${SET_SCREENSHOT_FUNCTION_NAME}(${JSON.stringify(screenshotData)})`,
279
- contextId
280
- });
281
- }
282
-
283
- async function onCapturePdf({ Page, Runtime }, contextId, options = {}) {
284
- const { data } = await Page.printToPDF(options);
285
- const pdfData = Array.from(new Uint8Array(await (await fetch("data:application/pdf;base64," + data)).arrayBuffer()));
286
- await Runtime.evaluate({
287
- expression: `globalThis.${SET_PDF_FUNCTION_NAME}(${JSON.stringify(pdfData)})`,
288
- contextId
289
- });
290
- }
291
-
292
- function getPageDataScriptSource(options, [SET_SCREENSHOT_FUNCTION_NAME, SET_PDF_FUNCTION_NAME, SET_PAGE_DATA_FUNCTION_NAME]) {
293
- if ((options.embedScreenshot && options.compressContent) || options.embedPdf) {
278
+ function getPageDataScriptSource(options, [SET_SCREENSHOT_FUNCTION_NAME, SET_PDF_FUNCTION_NAME, SET_PAGE_DATA_FUNCTION_NAME, CAPTURE_SCREENSHOT_FUNCTION_NAME, PRINT_TO_PDF_FUNCTION_NAME]) {
279
+ if ((options.embedScreenshot || options.embedPdf) && options.compressContent) {
294
280
  let screenshot, pdf;
295
- if (options.embedScreenshot && options.compressContent) {
296
- screenshot = new Promise(resolve => globalThis[SET_SCREENSHOT_FUNCTION_NAME] = resolve);
281
+ if (options.embedScreenshot) {
282
+ screenshot = new Promise(resolve => globalThis[SET_SCREENSHOT_FUNCTION_NAME] = async data =>
283
+ resolve(Array.from(new Uint8Array(await (await fetch("data:image/png;base64," + data)).arrayBuffer()))));
297
284
  }
298
285
  if (options.embedPdf) {
299
- pdf = new Promise(resolve => globalThis[SET_PDF_FUNCTION_NAME] = resolve);
286
+ pdf = new Promise(resolve => globalThis[SET_PDF_FUNCTION_NAME] = async data =>
287
+ resolve(Array.from(new Uint8Array(await (await fetch("data:application/pdf;base64," + data)).arrayBuffer()))));
300
288
  }
301
289
  let pendingCapture;
302
290
  options.onprogress = async event => {
303
291
  if (event.type == event.RESOURCES_INITIALIZING && window == top && !pendingCapture) {
304
292
  pendingCapture = true;
305
- if (globalThis.captureScreenshot) {
306
- globalThis.captureScreenshot("");
293
+ if (globalThis[CAPTURE_SCREENSHOT_FUNCTION_NAME]) {
294
+ globalThis[CAPTURE_SCREENSHOT_FUNCTION_NAME]("");
307
295
  options.embeddedImage = await screenshot;
308
296
  }
309
- if (globalThis.capturePdf) {
310
- globalThis.capturePdf("");
297
+ if (globalThis[PRINT_TO_PDF_FUNCTION_NAME]) {
298
+ globalThis[PRINT_TO_PDF_FUNCTION_NAME]("");
311
299
  options.embeddedPdf = await pdf;
312
300
  }
313
301
  }