single-file-cli 2.0.48 → 2.0.50
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/cdp-client.js +43 -4
- package/lib/single-file-bundle.js +1 -1
- package/lib/version.js +1 -1
- package/options.js +4 -1
- package/package.json +1 -1
- package/single-file-cli-api.js +28 -9
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.50";
|
package/options.js
CHANGED
|
@@ -97,6 +97,8 @@ const OPTIONS_INFO = {
|
|
|
97
97
|
"http-proxy-password": { description: "HTTP password", type: "string" },
|
|
98
98
|
"include-BOM": { description: "Include the UTF-8 BOM into the HTML page", type: "boolean" },
|
|
99
99
|
"include-infobar": { description: "Include the infobar", type: "boolean" },
|
|
100
|
+
"infobar-template": { description: "Template used to generate the infobar content (see help page of the extension for more info)", type: "string" },
|
|
101
|
+
"open-infobar": { description: "Keep the infobar open when using --include-infobar", type: "boolean" },
|
|
100
102
|
"insert-meta-CSP": { description: "Include a <meta> tag with a CSP to avoid potential requests to internet when viewing a page", type: "boolean", defaultValue: true },
|
|
101
103
|
"load-deferred-images": { description: "Load deferred (a.k.a. lazy-loaded) images", type: "boolean", defaultValue: true },
|
|
102
104
|
"load-deferred-images-dispatch-scroll-event": { description: "Dispatch 'scroll' event when loading deferred images", type: "boolean" },
|
|
@@ -131,7 +133,8 @@ const OPTIONS_INFO = {
|
|
|
131
133
|
"prevent-appended-data": { description: "Prevent appending data after the compressed data when creating self-extracting HTML files", type: "boolean" },
|
|
132
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" },
|
|
133
135
|
"output-directory": { description: "Path to where to save files, this path must exist.", type: "string" },
|
|
134
|
-
"version": { description: "Print the version number and exit.", type: "boolean" }
|
|
136
|
+
"version": { description: "Print the version number and exit.", type: "boolean" },
|
|
137
|
+
"output-json": { description: "Output the result as a JSON string containing the page and network info", type: "boolean" },
|
|
135
138
|
};
|
|
136
139
|
|
|
137
140
|
const { args, exit } = Deno;
|
package/package.json
CHANGED
package/single-file-cli-api.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* Source.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
/* global URL */
|
|
24
|
+
/* global URL, Blob, FileReader */
|
|
25
25
|
|
|
26
26
|
import * as backend from "./lib/cdp-client.js";
|
|
27
27
|
import { getZipScriptSource } from "./lib/single-file-script.js";
|
|
@@ -244,29 +244,48 @@ function getHostURL(url) {
|
|
|
244
244
|
|
|
245
245
|
async function capturePage(options) {
|
|
246
246
|
try {
|
|
247
|
-
let filename;
|
|
247
|
+
let filename, content;
|
|
248
248
|
options.zipScript = getZipScriptSource();
|
|
249
249
|
const pageData = await backend.getPageData(options);
|
|
250
|
+
filename = pageData.filename;
|
|
251
|
+
content = pageData.content;
|
|
252
|
+
if (options.outputJson) {
|
|
253
|
+
if (content instanceof Uint8Array) {
|
|
254
|
+
const fileReader = new FileReader();
|
|
255
|
+
fileReader.readAsDataURL(new Blob([content]));
|
|
256
|
+
content = await new Promise(resolve => {
|
|
257
|
+
fileReader.onload = () => resolve(fileReader.result);
|
|
258
|
+
});
|
|
259
|
+
content = content.replace(/^data:.*?;base64,/, "");
|
|
260
|
+
pageData.content = undefined;
|
|
261
|
+
pageData.binaryContent = content;
|
|
262
|
+
}
|
|
263
|
+
pageData.doctype = undefined;
|
|
264
|
+
pageData.viewport = undefined;
|
|
265
|
+
pageData.comment = undefined;
|
|
266
|
+
filename += filename.endsWith(".json") ? "" : ".json";
|
|
267
|
+
content = JSON.stringify(pageData, null, 2);
|
|
268
|
+
}
|
|
250
269
|
if (options.output) {
|
|
251
270
|
filename = await getFilename(options.output, options);
|
|
252
271
|
} else if (options.dumpContent) {
|
|
253
272
|
if (options.compressContent) {
|
|
254
|
-
await stdout.write(
|
|
273
|
+
await stdout.write(content);
|
|
255
274
|
} else {
|
|
256
|
-
console.log(
|
|
275
|
+
console.log(content || ""); // eslint-disable-line no-console
|
|
257
276
|
}
|
|
258
277
|
} else {
|
|
259
|
-
filename = await getFilename(
|
|
278
|
+
filename = await getFilename(filename, options);
|
|
260
279
|
}
|
|
261
|
-
if (filename) {
|
|
280
|
+
if (filename && !options.dumpContent) {
|
|
262
281
|
const directoryName = await path.dirname(filename);
|
|
263
282
|
if (directoryName !== ".") {
|
|
264
283
|
await mkdir(directoryName, { recursive: true });
|
|
265
284
|
}
|
|
266
|
-
if (
|
|
267
|
-
await writeFile(filename,
|
|
285
|
+
if (content instanceof Uint8Array) {
|
|
286
|
+
await writeFile(filename, content);
|
|
268
287
|
} else {
|
|
269
|
-
await writeTextFile(filename,
|
|
288
|
+
await writeTextFile(filename, content);
|
|
270
289
|
}
|
|
271
290
|
}
|
|
272
291
|
return pageData;
|