single-file-cli 2.0.69 → 2.0.70

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.70";
package/options.js CHANGED
@@ -42,6 +42,7 @@ 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" },
@@ -67,6 +68,7 @@ const OPTIONS_INFO = {
67
68
  "browser-device-height": { description: "Height of the device viewport in pixels (default value is 800 when using --browser-mobile-emulation)", type: "number" },
68
69
  "browser-device-scale-factor": { description: "Scale factor of the device viewport (default value is 2 when using --browser-mobile-emulation)", type: "number" },
69
70
  "console-messages-file": { description: "Path of the file where to save the console messages in JSON format", type: "string" },
71
+ "debug-messages-file": { description: "Path of the file where to save the debug messages", type: "string" },
70
72
  "compress-CSS": { description: "Compress CSS stylesheets", type: "boolean" },
71
73
  "compress-HTML": { description: "Compress HTML content", type: "boolean", defaultValue: true },
72
74
  "crawl-links": { description: "Crawl and save pages found via inner links", type: "boolean" },
@@ -146,7 +148,7 @@ const OPTIONS_INFO = {
146
148
  "resolve-links": { description: "Resolve link URLs to absolute URLs", type: "boolean", defaultValue: true },
147
149
  "settings-file": { description: "Path to a JSON file containing the settings exported from the web extension", type: "string" },
148
150
  "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 }
151
+ "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
152
  };
151
153
 
152
154
  const { args, exit } = Deno;
@@ -189,7 +191,7 @@ function getOptions() {
189
191
  return { ...options, url: positionals[0], output: positionals[1] };
190
192
  }
191
193
 
192
- function parseArgs(args) {
194
+ function parseArgs(args, setDefaultValues = true) {
193
195
  const positionals = [];
194
196
  const options = {};
195
197
  const result = { positionals, options: {} };
@@ -244,20 +246,33 @@ function parseArgs(args) {
244
246
  }
245
247
  result.options[optionKey] = optionValue;
246
248
  });
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
- };
249
+ if (setDefaultValues) {
250
+ Object.keys(OPTIONS_INFO).forEach(optionName => {
251
+ const optionInfo = getOptionInfo(optionName);
252
+ const optionKey = getOptionKey(optionName, optionInfo);
253
+ if (result.options[optionKey] === undefined && optionInfo.defaultValue !== undefined) {
254
+ result.options[optionKey] = OPTIONS_INFO[optionName].defaultValue;
255
+ }
256
+ });
257
+ }
258
+ if (result.options.acceptHeaderFont ||
259
+ result.options.acceptHeaderImage ||
260
+ result.options.acceptHeaderStylesheet ||
261
+ result.options.acceptHeaderScript ||
262
+ result.options.acceptHeaderDocument) {
263
+ result.options.acceptHeaders = {
264
+ font: result.options.acceptHeaderFont,
265
+ image: result.options.acceptHeaderImage,
266
+ stylesheet: result.options.acceptHeaderStylesheet,
267
+ script: result.options.acceptHeaderScript,
268
+ document: result.options.acceptHeaderDocument
269
+ };
270
+ delete result.options.acceptHeaderFont;
271
+ delete result.options.acceptHeaderImage;
272
+ delete result.options.acceptHeaderStylesheet;
273
+ delete result.options.acceptHeaderScript;
274
+ delete result.options.acceptHeaderDocument;
275
+ }
261
276
  if (result.options.browserArgs) {
262
277
  const browserArguments = result.options.browserArguments || [];
263
278
  browserArguments.push(...JSON.parse(result.options.browserArgs));
@@ -304,11 +319,10 @@ function parseArgs(args) {
304
319
  result.options.insertMetaCSP = result.options.insertMetaCsp;
305
320
  delete result.options.insertMetaCsp;
306
321
  }
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;
322
+ if (result.options.blockedUrlPatterns) {
323
+ result.options.blockedURLPatterns = result.options.blockedUrlPatterns;
324
+ delete result.options.blockedUrlPatterns;
325
+ }
312
326
  return result;
313
327
  }
314
328
 
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.70",
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,
@@ -262,6 +263,10 @@ async function capturePage(options) {
262
263
  if (options.consoleMessagesFile && pageData.consoleMessages) {
263
264
  await writeTextFile(options.consoleMessagesFile, JSON.stringify(pageData.consoleMessages, null, 2));
264
265
  }
266
+ if (options.debugMessagesFile && pageData.debugMessages) {
267
+ await writeTextFile(options.debugMessagesFile, pageData.debugMessages.map(([timestamp, message]) =>
268
+ `[${new Date(timestamp).toISOString()}] ${message.join(" ")}`).join("\n"));
269
+ }
265
270
  if (options.outputJson) {
266
271
  if (content instanceof Uint8Array) {
267
272
  const fileReader = new FileReader();
@@ -316,6 +321,13 @@ async function capturePage(options) {
316
321
  } else {
317
322
  console.error(error.message || error, message); // eslint-disable-line no-console
318
323
  }
324
+ if (options.consoleMessagesFile && error.consoleMessages) {
325
+ await writeTextFile(options.consoleMessagesFile, JSON.stringify(error.consoleMessages, null, 2));
326
+ }
327
+ if (options.debugMessagesFile && error.debugMessages) {
328
+ await writeTextFile(options.debugMessagesFile, error.debugMessages.map(([timestamp, message]) =>
329
+ `[${new Date(timestamp).toISOString()}] ${message.join(" ")}`).join("\n"));
330
+ }
319
331
  }
320
332
  }
321
333
 
@@ -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;