single-file-cli 2.0.63 → 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/compile.sh +1 -1
- package/deno.json +1 -1
- package/lib/cdp-client.js +32 -44
- package/lib/version.js +1 -1
- package/options.js +1 -0
- package/package.json +1 -1
- package/resources/single-file.ico +0 -0
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
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
|
|
36
|
+
const PRINT_TO_PDF_FUNCTION_NAME = "printToPDF";
|
|
37
37
|
const SET_SCREENSHOT_FUNCTION_NAME = "setScreenshot";
|
|
38
|
-
const SET_PDF_FUNCTION_NAME = "
|
|
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
|
-
|
|
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:
|
|
229
|
+
await Runtime.addBinding({ name: PRINT_TO_PDF_FUNCTION_NAME, executionContextId: contextId });
|
|
223
230
|
Runtime.addEventListener("bindingCalled", async ({ params }) => {
|
|
224
|
-
if (params.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
|
-
|
|
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
|
-
|
|
274
|
-
|
|
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
|
|
296
|
-
screenshot = new Promise(resolve => globalThis[SET_SCREENSHOT_FUNCTION_NAME] =
|
|
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] =
|
|
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
|
|
306
|
-
globalThis
|
|
293
|
+
if (globalThis[CAPTURE_SCREENSHOT_FUNCTION_NAME]) {
|
|
294
|
+
globalThis[CAPTURE_SCREENSHOT_FUNCTION_NAME]("");
|
|
307
295
|
options.embeddedImage = await screenshot;
|
|
308
296
|
}
|
|
309
|
-
if (globalThis
|
|
310
|
-
globalThis
|
|
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
|
}
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.64";
|
package/options.js
CHANGED
|
@@ -132,6 +132,7 @@ const OPTIONS_INFO = {
|
|
|
132
132
|
"extract-data-from-page": { description: "Extract compressed data from the page instead of fetching the page in order to create universal self-extracting HTML files", type: "boolean", defaultValue: true },
|
|
133
133
|
"prevent-appended-data": { description: "Prevent appending data after the compressed data when creating self-extracting HTML files", type: "boolean" },
|
|
134
134
|
"embed-screenshot": { description: "Embed a screenshot of the page as a PNG file in the compressed file (self-extracting HTML or ZIP file). When enabled, the resulting file can be read as a ZIP file or a PNG image.", type: "boolean" },
|
|
135
|
+
"embed-screenshot-options": { description: "Options passed to the CDP method `Page.captureScreenshot()` given as a JSON string (e.g. { \"captureBeyondViewport\": false })", type: "string" },
|
|
135
136
|
"embedded-image": { description: "Path to a PNG image to embed in the compressed file.", type: "string" },
|
|
136
137
|
"embed-pdf": { description: "Embed a PDF file in the ZIP or self-extracting file. When enabled, the resulting file can be read as a ZIP file or a PDF file.", type: "boolean" },
|
|
137
138
|
"embed-pdf-options": { description: "Options passed to the CDP method `Page.printToPDF()` given as a JSON string (e.g. { \"pageRanges\": \"1-1\", \"paperWidth\": 11, \"paperHeight\": 8.5 })", type: "string" },
|
package/package.json
CHANGED
|
Binary file
|