single-file-cli 2.0.69 → 2.0.71

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/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "2.0.69";
1
+ export const version = "2.0.71";
package/options.js CHANGED
@@ -42,12 +42,14 @@ const OPTIONS_INFO = {
42
42
  "block-scripts": { description: "Block scripts", type: "boolean", defaultValue: true },
43
43
  "block-videos": { description: "Block videos", type: "boolean", defaultValue: true },
44
44
  "block-mixed-content": { description: "Block mixed contents", type: "boolean" },
45
+ "blocked-URL-pattern": { description: "Regular expression matching URLs to block (e.g. 'annoying-banners\\.com')", type: "string[]" },
45
46
  "browser-server": { description: "Server to connect to", type: "string" },
46
47
  "browser-headless": { description: "Run the browser in headless mode", type: "boolean", defaultValue: true },
47
48
  "browser-executable-path": { description: "Path to chrome/chromium executable", type: "string" },
48
49
  "browser-width": { description: "Width of the browser viewport in pixels", type: "number", defaultValue: 1280 },
49
50
  "browser-height": { description: "Height of the browser viewport in pixels", type: "number", defaultValue: 720 },
50
- "browser-load-max-time": { description: "Maximum delay of time to wait for page loading in ms", type: "number", defaultValue: 60000 },
51
+ "browser-load-max-time": { description: "Maximum delay of time to wait for loading the page in ms", type: "number", defaultValue: 60000 },
52
+ "browser-capture-max-time": { description: "Maximum delay of time to wait for capturing the page in ms", type: "number", defaultValue: 60000 },
51
53
  "browser-wait-delay": { description: "Time to wait before capturing the page in ms", type: "number" },
52
54
  "browser-wait-until": { description: "When to consider the page is loaded (InteractiveTime, networkIdle, networkAlmostIdle, load, domContentLoaded)", type: "string", defaultValue: "networkIdle" },
53
55
  "browser-wait-until-delay": { description: "Delay of time in ms to wait before considering the page is loaded when the value of --browser-wait-until is reached", type: "number", defaultValue: 1000 },
@@ -67,6 +69,7 @@ const OPTIONS_INFO = {
67
69
  "browser-device-height": { description: "Height of the device viewport in pixels (default value is 800 when using --browser-mobile-emulation)", type: "number" },
68
70
  "browser-device-scale-factor": { description: "Scale factor of the device viewport (default value is 2 when using --browser-mobile-emulation)", type: "number" },
69
71
  "console-messages-file": { description: "Path of the file where to save the console messages in JSON format", type: "string" },
72
+ "debug-messages-file": { description: "Path of the file where to save the debug messages", type: "string" },
70
73
  "compress-CSS": { description: "Compress CSS stylesheets", type: "boolean" },
71
74
  "compress-HTML": { description: "Compress HTML content", type: "boolean", defaultValue: true },
72
75
  "crawl-links": { description: "Crawl and save pages found via inner links", type: "boolean" },
@@ -146,7 +149,7 @@ const OPTIONS_INFO = {
146
149
  "resolve-links": { description: "Resolve link URLs to absolute URLs", type: "boolean", defaultValue: true },
147
150
  "settings-file": { description: "Path to a JSON file containing the settings exported from the web extension", type: "string" },
148
151
  "settings-file-profile": { description: "Name of the profile to use when using --settings-file", type: "string", defaultValue: "default" },
149
- "group-duplicate-stylesheets": { description: "Group duplicate inline stylesheets into a single stylesheet in order to reduce the size of the page", type: "boolean", defaultValue: true }
152
+ "group-duplicate-stylesheets": { description: "Group duplicate inline stylesheets into a single stylesheet in order to reduce the size of the page", type: "boolean", defaultValue: false }
150
153
  };
151
154
 
152
155
  const { args, exit } = Deno;
@@ -189,7 +192,7 @@ function getOptions() {
189
192
  return { ...options, url: positionals[0], output: positionals[1] };
190
193
  }
191
194
 
192
- function parseArgs(args) {
195
+ function parseArgs(args, setDefaultValues = true) {
193
196
  const positionals = [];
194
197
  const options = {};
195
198
  const result = { positionals, options: {} };
@@ -244,20 +247,33 @@ function parseArgs(args) {
244
247
  }
245
248
  result.options[optionKey] = optionValue;
246
249
  });
247
- Object.keys(OPTIONS_INFO).forEach(optionName => {
248
- const optionInfo = getOptionInfo(optionName);
249
- const optionKey = getOptionKey(optionName, optionInfo);
250
- if (result.options[optionKey] === undefined && optionInfo.defaultValue !== undefined) {
251
- result.options[optionKey] = OPTIONS_INFO[optionName].defaultValue;
252
- }
253
- });
254
- result.options.acceptHeaders = {
255
- font: result.options.acceptHeaderFont,
256
- image: result.options.acceptHeaderImage,
257
- stylesheet: result.options.acceptHeaderStylesheet,
258
- script: result.options.acceptHeaderScript,
259
- document: result.options.acceptHeaderDocument
260
- };
250
+ if (setDefaultValues) {
251
+ Object.keys(OPTIONS_INFO).forEach(optionName => {
252
+ const optionInfo = getOptionInfo(optionName);
253
+ const optionKey = getOptionKey(optionName, optionInfo);
254
+ if (result.options[optionKey] === undefined && optionInfo.defaultValue !== undefined) {
255
+ result.options[optionKey] = OPTIONS_INFO[optionName].defaultValue;
256
+ }
257
+ });
258
+ }
259
+ if (result.options.acceptHeaderFont ||
260
+ result.options.acceptHeaderImage ||
261
+ result.options.acceptHeaderStylesheet ||
262
+ result.options.acceptHeaderScript ||
263
+ result.options.acceptHeaderDocument) {
264
+ result.options.acceptHeaders = {
265
+ font: result.options.acceptHeaderFont,
266
+ image: result.options.acceptHeaderImage,
267
+ stylesheet: result.options.acceptHeaderStylesheet,
268
+ script: result.options.acceptHeaderScript,
269
+ document: result.options.acceptHeaderDocument
270
+ };
271
+ delete result.options.acceptHeaderFont;
272
+ delete result.options.acceptHeaderImage;
273
+ delete result.options.acceptHeaderStylesheet;
274
+ delete result.options.acceptHeaderScript;
275
+ delete result.options.acceptHeaderDocument;
276
+ }
261
277
  if (result.options.browserArgs) {
262
278
  const browserArguments = result.options.browserArguments || [];
263
279
  browserArguments.push(...JSON.parse(result.options.browserArgs));
@@ -304,11 +320,10 @@ function parseArgs(args) {
304
320
  result.options.insertMetaCSP = result.options.insertMetaCsp;
305
321
  delete result.options.insertMetaCsp;
306
322
  }
307
- delete result.options.acceptHeaderFont;
308
- delete result.options.acceptHeaderImage;
309
- delete result.options.acceptHeaderStylesheet;
310
- delete result.options.acceptHeaderScript;
311
- delete result.options.acceptHeaderDocument;
323
+ if (result.options.blockedUrlPatterns) {
324
+ result.options.blockedURLPatterns = result.options.blockedUrlPatterns;
325
+ delete result.options.blockedUrlPatterns;
326
+ }
312
327
  return result;
313
328
  }
314
329
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.69",
3
+ "version": "2.0.71",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -39,8 +39,9 @@ const DEFAULT_OPTIONS = {
39
39
  filenameTemplate: "{page-title} ({date-locale} {time-locale}).html",
40
40
  filenameMaxLength: 192,
41
41
  filenameMaxLengthUnit: "bytes",
42
- filenameReplacedCharacters: ["~", "+", "\\\\", "?", "%", "*", ":", "|", "\"", "<", ">", "\x00-\x1f", "\x7F"],
42
+ filenameReplacedCharacters: ["~", "+", "?", "%", "*", ":", "|", "\"", "<", ">", "\\\\", "\x00-\x1f", "\x7F"],
43
43
  filenameReplacementCharacter: "_",
44
+ filenameReplacementCharacters: ["~", "+", "?", "%", "*", ":", "|", """, "<", ">", "\"],
44
45
  maxResourceSize: 10,
45
46
  backgroundSave: true,
46
47
  removeAlternativeFonts: true,
@@ -194,6 +195,7 @@ function testMaxDepth(task) {
194
195
  }
195
196
 
196
197
  async function createTask(url, options, parentTask, rootTaskURL) {
198
+ options.originalUrl = url;
197
199
  url = parentTask ? rewriteURL(url, options.crawlRemoveURLFragment, options.crawlRewriteRules) : url;
198
200
  if (url) {
199
201
  if (!VALID_URL_TEST.test(url)) {
@@ -262,6 +264,10 @@ async function capturePage(options) {
262
264
  if (options.consoleMessagesFile && pageData.consoleMessages) {
263
265
  await writeTextFile(options.consoleMessagesFile, JSON.stringify(pageData.consoleMessages, null, 2));
264
266
  }
267
+ if (options.debugMessagesFile && pageData.debugMessages) {
268
+ await writeTextFile(options.debugMessagesFile, pageData.debugMessages.map(([timestamp, message]) =>
269
+ `[${new Date(timestamp).toISOString()}] ${message.join(" ")}`).join("\n"));
270
+ }
265
271
  if (options.outputJson) {
266
272
  if (content instanceof Uint8Array) {
267
273
  const fileReader = new FileReader();
@@ -316,6 +322,13 @@ async function capturePage(options) {
316
322
  } else {
317
323
  console.error(error.message || error, message); // eslint-disable-line no-console
318
324
  }
325
+ if (options.consoleMessagesFile && error.consoleMessages) {
326
+ await writeTextFile(options.consoleMessagesFile, JSON.stringify(error.consoleMessages, null, 2));
327
+ }
328
+ if (options.debugMessagesFile && error.debugMessages) {
329
+ await writeTextFile(options.debugMessagesFile, error.debugMessages.map(([timestamp, message]) =>
330
+ `[${new Date(timestamp).toISOString()}] ${message.join(" ")}`).join("\n"));
331
+ }
319
332
  }
320
333
  }
321
334
 
@@ -182,7 +182,7 @@ async function getUrlsFile(urlsFile) {
182
182
  if (lastCharIndex < argsString.length) {
183
183
  args.push(argsString.substring(lastCharIndex).trim());
184
184
  }
185
- const { options } = parseArgs(args);
185
+ const { options } = parseArgs(args, false);
186
186
  return [url, options];
187
187
  } else {
188
188
  return value;