single-file-core 1.3.30 → 1.3.32

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/core/index.js CHANGED
@@ -177,7 +177,7 @@ class Runner {
177
177
  const rootDocDefined = root && options.doc;
178
178
  this.root = root;
179
179
  this.options = options;
180
- this.options.url = this.options.url || (rootDocDefined && this.options.doc.location.href);
180
+ this.options.url = this.options.url || (rootDocDefined && this.options.doc.documentURI);
181
181
  const matchResourceReferrer = this.options.url.match(/^.*\//);
182
182
  this.options.resourceReferrer = this.options.passReferrerOnError && matchResourceReferrer && matchResourceReferrer[0];
183
183
  this.options.baseURI = rootDocDefined && this.options.doc.baseURI;
@@ -209,13 +209,13 @@ class Runner {
209
209
  }
210
210
 
211
211
  async loadPage() {
212
- this.onprogress(new ProgressEvent(PAGE_LOADING, { pageURL: this.options.url, frame: !this.root }));
212
+ await this.onprogress(new ProgressEvent(PAGE_LOADING, { pageURL: this.options.url, frame: !this.root, options: this.options, }));
213
213
  await this.processor.loadPage(this.options.content);
214
- this.onprogress(new ProgressEvent(PAGE_LOADED, { pageURL: this.options.url, frame: !this.root }));
214
+ await this.onprogress(new ProgressEvent(PAGE_LOADED, { pageURL: this.options.url, frame: !this.root, options: this.options }));
215
215
  }
216
216
 
217
217
  async initialize() {
218
- this.onprogress(new ProgressEvent(RESOURCES_INITIALIZING, { pageURL: this.options.url }));
218
+ await this.onprogress(new ProgressEvent(RESOURCES_INITIALIZING, { pageURL: this.options.url, options: this.options }));
219
219
  await this.executeStage(RESOLVE_URLS_STAGE);
220
220
  this.pendingPromises = this.executeStage(REPLACE_DATA_STAGE);
221
221
  if (this.root && this.options.doc) {
@@ -242,11 +242,12 @@ class Runner {
242
242
  async run() {
243
243
  if (this.root) {
244
244
  this.processor.initialize(this.batchRequest);
245
- this.onprogress(new ProgressEvent(RESOURCES_INITIALIZED, { pageURL: this.options.url, max: this.processor.maxResources }));
245
+ await this.onprogress(new ProgressEvent(RESOURCES_INITIALIZED, { pageURL: this.options.url, max: this.processor.maxResources, options: this.options }));
246
246
  }
247
- await this.batchRequest.run(detail => {
247
+ await this.batchRequest.run(async detail => {
248
248
  detail.pageURL = this.options.url;
249
- this.onprogress(new ProgressEvent(RESOURCE_LOADED, detail));
249
+ detail.options = this.options;
250
+ await this.onprogress(new ProgressEvent(RESOURCE_LOADED, detail));
250
251
  }, this.options);
251
252
  await this.pendingPromises;
252
253
  this.options.doc = null;
@@ -265,9 +266,9 @@ class Runner {
265
266
  return this.processor.stylesheets;
266
267
  }
267
268
 
268
- getPageData() {
269
+ async getPageData() {
269
270
  if (this.root) {
270
- this.onprogress(new ProgressEvent(PAGE_ENDED, { pageURL: this.options.url }));
271
+ await this.onprogress(new ProgressEvent(PAGE_ENDED, { pageURL: this.options.url, options: this.options }));
271
272
  }
272
273
  return this.processor.getPageData();
273
274
  }
@@ -277,22 +278,22 @@ class Runner {
277
278
  log("**** STARTED STAGE", step, "****");
278
279
  }
279
280
  const frame = !this.root;
280
- this.onprogress(new ProgressEvent(STAGE_STARTED, { pageURL: this.options.url, step, frame }));
281
- STAGES[step].sequential.forEach(task => {
281
+ await this.onprogress(new ProgressEvent(STAGE_STARTED, { pageURL: this.options.url, step, frame, options: this.options }));
282
+ for (const task of STAGES[step].sequential) {
282
283
  let startTime;
283
284
  if (DEBUG) {
284
285
  startTime = Date.now();
285
286
  log(" -- STARTED task =", task.action);
286
287
  }
287
- this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, step, task: task.action, frame }));
288
+ await this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, step, task: task.action, frame, options: this.options }));
288
289
  if (!this.cancelled) {
289
290
  this.executeTask(task);
290
291
  }
291
- this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action, frame }));
292
+ await this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action, frame, options: this.options }));
292
293
  if (DEBUG) {
293
294
  log(" -- ENDED task =", task.action, "delay =", Date.now() - startTime);
294
295
  }
295
- });
296
+ }
296
297
  let parallelTasksPromise;
297
298
  if (STAGES[step].parallel) {
298
299
  parallelTasksPromise = await Promise.all(STAGES[step].parallel.map(async task => {
@@ -301,11 +302,11 @@ class Runner {
301
302
  startTime = Date.now();
302
303
  log(" // STARTED task =", task.action);
303
304
  }
304
- this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, step, task: task.action, frame }));
305
+ await this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, step, task: task.action, frame, options: this.options }));
305
306
  if (!this.cancelled) {
306
307
  await this.executeTask(task);
307
308
  }
308
- this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action, frame }));
309
+ await this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action, frame, options: this.options }));
309
310
  if (DEBUG) {
310
311
  log(" // ENDED task =", task.action, "delay =", Date.now() - startTime);
311
312
  }
@@ -313,7 +314,7 @@ class Runner {
313
314
  } else {
314
315
  parallelTasksPromise = Promise.resolve();
315
316
  }
316
- this.onprogress(new ProgressEvent(STAGE_ENDED, { pageURL: this.options.url, step, frame }));
317
+ await this.onprogress(new ProgressEvent(STAGE_ENDED, { pageURL: this.options.url, step, frame, options: this.options }));
317
318
  if (DEBUG) {
318
319
  log("**** ENDED STAGE", step, "****");
319
320
  }
@@ -384,7 +385,7 @@ class BatchRequest {
384
385
  acceptHeaders: options.acceptHeaders,
385
386
  networkTimeout: options.networkTimeout
386
387
  });
387
- onloadListener({ url: resourceURL });
388
+ await onloadListener({ url: resourceURL });
388
389
  if (!this.cancelled) {
389
390
  const extension = util.getContentTypeExtension(content.contentType) || util.getFilenameExtension(resourceURL, options.filenameReplacedCharacters, options.filenameReplacementCharacter);
390
391
  resourceRequests.forEach(callbacks => {
@@ -395,7 +396,7 @@ class BatchRequest {
395
396
  }
396
397
  } catch (error) {
397
398
  indexResource = indexResource + 1;
398
- onloadListener({ url: resourceURL });
399
+ await onloadListener({ url: resourceURL });
399
400
  resourceRequests.forEach(resourceRequest => resourceRequest.reject(error));
400
401
  }
401
402
  this.requests.delete(requestKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.3.30",
3
+ "version": "1.3.32",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -253,6 +253,7 @@ async function prependHTMLData(pageData, zipDataWriter, script, options) {
253
253
  }
254
254
  const displayOptions = {
255
255
  insertEmbeddedImage: Boolean(options.embeddedImage),
256
+ insertEmbeddedScreenshotImage: Boolean(options.embeddedScreenshotImage)
256
257
  };
257
258
  script = "<script>" +
258
259
  script +
@@ -403,7 +403,7 @@ function getFrameData(document, globalThis, windowId, options, scrolling) {
403
403
  windowId,
404
404
  content,
405
405
  baseURI,
406
- url: document.location.href,
406
+ url: document.documentURI,
407
407
  title: document.title,
408
408
  canvases: docData.canvases,
409
409
  fonts: docData.fonts,
package/single-file.js CHANGED
@@ -110,7 +110,6 @@ async function getPageData(options = {}, initOptions, doc = globalThis.document,
110
110
  url: options.url,
111
111
  createRootDirectory: options.createRootDirectory,
112
112
  selfExtractingArchive: options.selfExtractingArchive,
113
- insertEmbeddedImage: options.insertEmbeddedImage,
114
113
  extractDataFromPage: options.extractDataFromPage,
115
114
  preventAppendedData: options.preventAppendedData,
116
115
  insertCanonicalLink: options.insertCanonicalLink,