single-file-core 1.0.67 → 1.0.69

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/common/infobar.js CHANGED
@@ -193,27 +193,9 @@ function appendInfobar(doc, options, useShadowRoot) {
193
193
  infobarContainer.appendChild(shadowRootContent);
194
194
  } else {
195
195
  const scriptElement = doc.createElement("script");
196
- let scriptContent = (refreshInfobarInfo.toString());
197
- scriptContent += (extractInfobarData.toString());
198
- scriptContent += "refreshInfobarInfo(document, extractInfobarData(document))";
199
- scriptContent = scriptContent
200
- .replace(/ == /g, "==")
201
- .replace(/ > /g, ">")
202
- .replace(/ < /g, "<")
203
- .replace(/ \+ /g, "+")
204
- .replace(/ - /g, "-")
205
- .replace(/ = /g, "=")
206
- .replace(/ \+= /g, "+=")
207
- .replace(/ && /g, "&&")
208
- .replace(/ \|\| /g, "||")
209
- .replace(/{ /g, "{")
210
- .replace(/ }/g, "}")
211
- .replace(/, /g, ",")
212
- .replace(/; /g, ";")
213
- .replace(/ \(/g, "(")
214
- .replace(/ \)/g, ")")
215
- .replace(/\t/g, "")
216
- .replace(/\n/g, "");
196
+ let scriptContent = refreshInfobarInfo.toString();
197
+ scriptContent += extractInfobarData.toString();
198
+ scriptContent += "(" + initInfobar.toString() + ")(document)";
217
199
  scriptElement.textContent = scriptContent;
218
200
  shadowRootContent.appendChild(scriptElement);
219
201
  infobarContainer.innerHTML = shadowRootContent.outerHTML;
@@ -269,6 +251,13 @@ function displayIcon(doc, useShadowRoot) {
269
251
  }
270
252
  }
271
253
 
254
+ function initInfobar(doc) {
255
+ const infoData = extractInfobarData(doc);
256
+ if (infoData && infoData.saveUrl) {
257
+ refreshInfobarInfo(doc, infoData);
258
+ }
259
+ }
260
+
272
261
  function createElement(doc, tagName, parentElement) {
273
262
  const element = doc.createElement(tagName);
274
263
  parentElement.appendChild(element);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.0.67",
3
+ "version": "1.0.69",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -173,7 +173,7 @@ function initRequestSync(message) {
173
173
  if (message.options.userScriptEnabled && waitForUserScript) {
174
174
  waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME);
175
175
  }
176
- sendInitResponse({ frames: [getFrameData(document, globalThis, windowId, message.options)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
176
+ sendInitResponse({ frames: [getFrameData(document, globalThis, windowId, message.options, message.scrolling)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
177
177
  if (message.options.userScriptEnabled && waitForUserScript) {
178
178
  waitForUserScript(helper.ON_AFTER_CAPTURE_EVENT_NAME);
179
179
  }
@@ -193,7 +193,7 @@ async function initRequestAsync(message) {
193
193
  if (message.options.userScriptEnabled && waitForUserScript) {
194
194
  await waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME);
195
195
  }
196
- sendInitResponse({ frames: [getFrameData(document, globalThis, windowId, message.options)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
196
+ sendInitResponse({ frames: [getFrameData(document, globalThis, windowId, message.options, message.scrolling)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
197
197
  if (message.options.userScriptEnabled && waitForUserScript) {
198
198
  await waitForUserScript(helper.ON_AFTER_CAPTURE_EVENT_NAME);
199
199
  }
@@ -236,6 +236,8 @@ function initResponse(message) {
236
236
  frameData.usedFonts = messageFrameData.usedFonts;
237
237
  frameData.shadowRoots = messageFrameData.shadowRoots;
238
238
  frameData.processed = messageFrameData.processed;
239
+ frameData.scrollPosition = messageFrameData.scrollPosition;
240
+ frameData.scrolling = messageFrameData.scrolling;
239
241
  }
240
242
  });
241
243
  const remainingFrames = windowData.frames.filter(frameData => !frameData.processed).length;
@@ -280,7 +282,7 @@ function processFramesAsync(doc, frameElements, options, parentWindowId, session
280
282
  frameElements.forEach((frameElement, frameIndex) => {
281
283
  const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
282
284
  try {
283
- sendMessage(frameElement.contentWindow, { method: INIT_REQUEST_MESSAGE, windowId, sessionId, options });
285
+ sendMessage(frameElement.contentWindow, { method: INIT_REQUEST_MESSAGE, windowId, sessionId, options, scrolling: frameElement.scrolling });
284
286
  } catch (error) {
285
287
  // ignored
286
288
  }
@@ -305,7 +307,7 @@ function processFramesSync(doc, frameElements, options, parentWindowId, sessionI
305
307
  frameWindow.stop();
306
308
  clearFrameTimeout("requestTimeouts", sessionId, windowId);
307
309
  processFrames(frameDoc, options, windowId, sessionId);
308
- frames.push(getFrameData(frameDoc, frameWindow, windowId, options));
310
+ frames.push(getFrameData(frameDoc, frameWindow, windowId, options, frameElement.scrolling));
309
311
  } catch (error) {
310
312
  frames.push({ windowId, processed: true });
311
313
  }
@@ -384,7 +386,7 @@ function sendMessage(targetWindow, message, useChannel) {
384
386
  }
385
387
  }
386
388
 
387
- function getFrameData(document, globalThis, windowId, options) {
389
+ function getFrameData(document, globalThis, windowId, options, scrolling) {
388
390
  const docData = helper.preProcessDoc(document, globalThis, options);
389
391
  const content = helper.serialize(document);
390
392
  helper.postProcessDoc(document, docData.markedElements, docData.invalidElements);
@@ -403,6 +405,8 @@ function getFrameData(document, globalThis, windowId, options) {
403
405
  videos: docData.videos,
404
406
  usedFonts: docData.usedFonts,
405
407
  shadowRoots: docData.shadowRoots,
408
+ scrollPosition: docData.scrollPosition,
409
+ scrolling,
406
410
  processed: true
407
411
  };
408
412
  }
@@ -114,6 +114,7 @@ const STAGES = [{
114
114
  { option: "removeFrames", action: "removeFrames" },
115
115
  { action: "removeDiscardedResources" },
116
116
  { option: "removeHiddenElements", action: "removeHiddenElements" },
117
+ { action: "saveScrollPosition" },
117
118
  { action: "resolveHrefs" },
118
119
  { action: "resolveStyleAttributeURLs" }
119
120
  ],
@@ -494,6 +495,10 @@ class Processor {
494
495
  );
495
496
  this.doc.documentElement.insertBefore(commentNode, this.doc.documentElement.firstChild);
496
497
  }
498
+ const legacyInfobarElement = this.doc.querySelector("singlefile-infobar");
499
+ if (legacyInfobarElement) {
500
+ legacyInfobarElement.remove();
501
+ }
497
502
  if (this.options.includeInfobar) {
498
503
  util.appendInfobar(this.doc, this.options);
499
504
  }
@@ -880,6 +885,14 @@ class Processor {
880
885
  this.doc.head.appendChild(faviconElement);
881
886
  }
882
887
 
888
+ saveScrollPosition() {
889
+ if (this.options.scrollPosition && this.options.scrolling == "no" && (this.options.scrollPosition.x || this.options.scrollPosition.y)) {
890
+ const scriptElement = this.doc.createElement("script");
891
+ scriptElement.textContent = "document.currentScript.remove();addEventListener(\"load\",()=>scrollTo(" + this.options.scrollPosition.x + "," + this.options.scrollPosition.y + "))";
892
+ this.doc.body.appendChild(scriptElement);
893
+ }
894
+ }
895
+
883
896
  replaceCanvasElements() {
884
897
  if (this.options.canvases) {
885
898
  this.doc.querySelectorAll("canvas").forEach(canvasElement => {
@@ -1130,6 +1143,7 @@ class Processor {
1130
1143
  options.insertCanonicalLink = false;
1131
1144
  options.insertMetaNoIndex = false;
1132
1145
  options.saveFavicon = false;
1146
+ options.includeInfobar = false;
1133
1147
  options.url = frameData.baseURI;
1134
1148
  options.windowId = frameWindowId;
1135
1149
  if (frameData.content) {
@@ -1142,6 +1156,8 @@ class Processor {
1142
1156
  options.videos = frameData.videos;
1143
1157
  options.usedFonts = frameData.usedFonts;
1144
1158
  options.shadowRoots = frameData.shadowRoots;
1159
+ options.scrollPosition = frameData.scrollPosition;
1160
+ options.scrolling = frameData.scrolling;
1145
1161
  frameData.runner = new Runner(options);
1146
1162
  frameData.frameElement = frameElement;
1147
1163
  await frameData.runner.loadPage();
@@ -182,7 +182,8 @@ function preProcessDoc(doc, win, options) {
182
182
  shadowRoots: elementsInfo.shadowRoots,
183
183
  referrer: doc.referrer,
184
184
  markedElements: elementsInfo.markedElements,
185
- invalidElements
185
+ invalidElements,
186
+ scrollPosition: { x: win.scrollX, y: win.scrollY }
186
187
  };
187
188
  }
188
189