single-file-core 1.5.34 → 1.5.36

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/helper.js CHANGED
@@ -131,7 +131,7 @@ export {
131
131
  };
132
132
 
133
133
  function initUserScriptHandler() {
134
- addEventListener(ON_INIT_USERSCRIPT_EVENT, () => globalThis[WAIT_FOR_USERSCRIPT_PROPERTY_NAME] = async (eventPrefixName, options) => {
134
+ addEventListener(ON_INIT_USERSCRIPT_EVENT, ({ detail }) => globalThis[WAIT_FOR_USERSCRIPT_PROPERTY_NAME] = async (eventPrefixName, options) => {
135
135
  const userScriptOptions = Object.assign({}, options);
136
136
  delete userScriptOptions.win;
137
137
  delete userScriptOptions.doc;
@@ -140,13 +140,26 @@ function initUserScriptHandler() {
140
140
  delete userScriptOptions.taskId;
141
141
  delete userScriptOptions._migratedTemplateFormat;
142
142
  delete userScriptOptions.woleetKey;
143
- const event = new CustomEvent(eventPrefixName + "-request", { cancelable: true, detail: { options: userScriptOptions } });
143
+ let detailUserScript;
144
+ try {
145
+ detailUserScript = detail == "jsonDetail" ? JSON.stringify({ options: userScriptOptions }) : { options: userScriptOptions };
146
+ } catch (error) {
147
+ // ignored
148
+ }
149
+ const event = new CustomEvent(eventPrefixName + "-request", { cancelable: true, detail: detailUserScript });
144
150
  let resolvePromiseResponse;
145
151
  const promiseResponse = new Promise(resolve => {
146
152
  resolvePromiseResponse = resolve;
147
153
  addEventListener(eventPrefixName + "-response", event => {
148
- if (event.detail && event.detail.options) {
149
- Object.assign(options, event.detail.options);
154
+ if (event.detail) {
155
+ try {
156
+ const detail = typeof event.detail == "string" ? JSON.parse(event.detail) : event.detail;
157
+ if (detail.options) {
158
+ Object.assign(options, detail.options);
159
+ }
160
+ } catch (error) {
161
+ // ignored
162
+ }
150
163
  }
151
164
  resolve();
152
165
  });
package/core/index.js CHANGED
@@ -179,7 +179,7 @@ class Runner {
179
179
  this.options.url = this.options.url || (rootDocDefined && this.options.doc.documentURI);
180
180
  const matchResourceReferrer = this.options.url.match(/^.*\//);
181
181
  this.options.resourceReferrer = this.options.passReferrerOnError && matchResourceReferrer && matchResourceReferrer[0];
182
- this.options.baseURI = rootDocDefined && this.options.doc.baseURI;
182
+ this.options.baseURI = rootDocDefined && (testValidURL(this.options.doc.baseURI) ? this.options.doc.baseURI : this.options.url);
183
183
  this.options.rootDocument = root;
184
184
  this.options.updatedResources = this.options.updatedResources || {};
185
185
  this.options.fontTests = new Map();
@@ -788,7 +788,7 @@ class Processor {
788
788
  const attributeValue = videoElement.getAttribute(util.VIDEO_ATTRIBUTE_NAME);
789
789
  if (attributeValue) {
790
790
  const videoData = this.options.videos[Number(attributeValue)];
791
- const src = videoData.src || videoElement.src;
791
+ const src = (videoData && videoData.src) || videoElement.src;
792
792
  if (videoElement && src) {
793
793
  const linkElement = this.doc.createElement("a");
794
794
  const imgElement = this.doc.createElement("img");
@@ -956,7 +956,11 @@ class Processor {
956
956
  this.doc.querySelectorAll("input, textarea").forEach(input => {
957
957
  const value = input.getAttribute(util.INPUT_VALUE_ATTRIBUTE_NAME);
958
958
  if (value != null) {
959
- input.setAttribute("value", value);
959
+ if (input.tagName.toUpperCase() == "TEXTAREA") {
960
+ input.textContent = value;
961
+ } else {
962
+ input.setAttribute("value", value);
963
+ }
960
964
  } else {
961
965
  input.removeAttribute("value");
962
966
  }
@@ -239,9 +239,9 @@ function getProcessorHelperClass(utilInstance) {
239
239
  }
240
240
 
241
241
  async processFrame(frameElement, pageData, options) {
242
- let sandbox = "allow-popups allow-top-navigation allow-top-navigation-by-user-activation";
242
+ let sandbox = "allow-popups allow-top-navigation-by-user-activation";
243
243
  if (pageData.content.match(NOSCRIPT_TAG_FOUND) || pageData.content.match(CANVAS_TAG_FOUND) || pageData.content.match(SCRIPT_TAG_FOUND) || options.saveRawPage) {
244
- sandbox += " allow-scripts allow-same-origin allow-modals allow-popups allow-downloads allow-pointer-lock allow-presentation";
244
+ sandbox += " allow-scripts allow-modals allow-popups allow-downloads allow-pointer-lock allow-presentation";
245
245
  }
246
246
  frameElement.setAttribute("sandbox", sandbox);
247
247
  if (frameElement.tagName.toUpperCase() == "OBJECT") {
@@ -445,7 +445,7 @@ function getProcessorHelperClass(utilInstance) {
445
445
  if (imageData && imageData.replaceable) {
446
446
  imgElement.setAttribute("src", `${PREFIX_DATA_URI_IMAGE_SVG},<svg xmlns="http://www.w3.org/2000/svg" width="${imageData.size.pxWidth}" height="${imageData.size.pxHeight}"><rect fill-opacity="0"/></svg>`);
447
447
  const backgroundStyle = {};
448
- const backgroundSize = (imageData.objectFit == "content" || imageData.objectFit == "cover") && imageData.objectFit;
448
+ const backgroundSize = (imageData.objectFit == "content" || imageData.objectFit == "cover" || imageData.objectFit == "contain") && imageData.objectFit;
449
449
  if (backgroundSize) {
450
450
  backgroundStyle["background-size"] = imageData.objectFit;
451
451
  }
@@ -235,9 +235,9 @@ function getProcessorHelperClass(utilInstance) {
235
235
 
236
236
  async processFrame(frameElement, pageData, options, resources, frameWindowId, frameData) {
237
237
  const name = "frames/" + resources.frames.size + "/";
238
- let sandbox = "allow-popups allow-top-navigation allow-top-navigation-by-user-activation";
238
+ let sandbox = "allow-popups allow-top-navigation-by-user-activation";
239
239
  if (pageData.content.match(NOSCRIPT_TAG_FOUND) || pageData.content.match(CANVAS_TAG_FOUND) || pageData.content.match(SCRIPT_TAG_FOUND) || options.saveRawPage) {
240
- sandbox += " allow-scripts allow-same-origin allow-modals allow-popups allow-downloads allow-pointer-lock allow-presentation";
240
+ sandbox += " allow-scripts allow-modals allow-popups allow-downloads allow-pointer-lock allow-presentation";
241
241
  }
242
242
  frameElement.setAttribute("sandbox", sandbox);
243
243
  if (frameElement.tagName.toUpperCase() == "OBJECT") {
@@ -75,7 +75,7 @@ function matchesMediaType(mediaText, keepPrintStyleSheets) {
75
75
  const foundMediaTypes = helper.flatten(mediaQueryParser.parseMediaList(mediaText).map(node => getMediaTypes(node)));
76
76
  return foundMediaTypes.find(mediaTypeInfo =>
77
77
  (!mediaTypeInfo.not && (mediaTypeInfo.value == MEDIA_SCREEN || mediaTypeInfo.value == MEDIA_ALL || (keepPrintStyleSheets && mediaTypeInfo.value == MEDIA_PRINT))) ||
78
- (mediaTypeInfo.not && (mediaTypeInfo.value != MEDIA_SCREEN)));
78
+ (mediaTypeInfo.not && (mediaTypeInfo.value != MEDIA_SCREEN || mediaText.includes(" and "))));
79
79
  }
80
80
 
81
81
  function getMediaTypes(parentNode, mediaTypes = []) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.34",
3
+ "version": "1.5.36",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -50,8 +50,7 @@ async function display(document, docContent, { disableFramePointerEvents } = {})
50
50
  element.parentElement.replaceChild(noscriptElement, element);
51
51
  });
52
52
  document.documentElement.setAttribute("data-sfz", "");
53
- document.querySelectorAll("link[rel*=icon]").forEach(element => element.parentElement.replaceChild(element, element));
54
-
53
+ document.querySelectorAll("link[rel*=icon]").forEach(element => element.replaceWith(element.cloneNode(true)));
55
54
  function getDoctypeString(doc) {
56
55
  const docType = doc.doctype;
57
56
  let docTypeString = "";
package/single-file.js CHANGED
@@ -48,7 +48,13 @@ function init(initOptions) {
48
48
  }
49
49
  }
50
50
 
51
- async function getPageData(options = {}, initOptions, doc = globalThis.document, win = globalThis) {
51
+ async function getPageData(options = {}, initOptions, doc, win) {
52
+ if (doc === undefined) {
53
+ doc = globalThis.document;
54
+ }
55
+ if (win === undefined) {
56
+ win = globalThis;
57
+ }
52
58
  const frames = processors.frameTree;
53
59
  let framesSessionId;
54
60
  init(initOptions);