single-file-core 1.5.35 → 1.5.37

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
@@ -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
  }
@@ -1216,7 +1220,7 @@ class Processor {
1216
1220
  }
1217
1221
  }
1218
1222
  });
1219
- await Promise.all(Array.from(this.doc.querySelectorAll("style, link[rel*=stylesheet]")).map(async element => {
1223
+ await Promise.all(Array.from(this.doc.querySelectorAll("style, link[rel*=stylesheet]:not([disabled])")).map(async element => {
1220
1224
  const options = Object.assign({}, this.options, { charset: this.charset });
1221
1225
  let mediaText;
1222
1226
  if (element.media) {
@@ -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.35",
3
+ "version": "1.5.37",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",