single-file-core 1.4.3 → 1.4.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -70,6 +70,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
70
70
  const REGEXP_MATCH_ROOT_INDEX = /^([0-9_]+\/)?index\.html$/;
71
71
  const REGEXP_MATCH_INDEX = /index\.html$/;
72
72
  const REGEXP_MATCH_FRAMES = /frames\//;
73
+ const REGEXP_MATCH_TOP_LEVEL_FRAME = /^frames\/\d+\/index.html/;
73
74
  const REGEXP_MATCH_MANIFEST = /manifest\.json$/;
74
75
  const CHARSET_UTF8 = ";charset=utf-8";
75
76
  const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
@@ -204,7 +205,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
204
205
  return { docContent, origDocContent, resources, url };
205
206
 
206
207
  async function getContent(resource) {
207
- return resource.filename.match(REGEXP_MATCH_FRAMES) || noBlobURL ? await getDataURI(resource.textContent, resource.mimeType) : URL.createObjectURL(new Blob([resource.textContent], { type: resource.mimeType }));
208
+ return resource.filename.match(REGEXP_MATCH_FRAMES) && !resource.filename.match(REGEXP_MATCH_TOP_LEVEL_FRAME) || noBlobURL ? await getDataURI(resource.textContent, resource.mimeType) : URL.createObjectURL(new Blob([resource.textContent], { type: resource.mimeType }));
208
209
  }
209
210
 
210
211
  async function getDataURI(textContent, mimeType) {
@@ -228,11 +228,13 @@ async function prependHTMLData(pageData, zipDataWriter, script, options) {
228
228
  pageContent += getHTMLStartData(pageData, options);
229
229
  }
230
230
  pageContent += "<div id=sfz-wait-message>Please wait...</div>";
231
- pageContent += "<div id=sfz-error-message><strong>Error</strong>: Cannot open the page from the filesystem.";
232
- pageContent += "<ul style='line-height:20px;'>";
233
- pageContent += "<li style='margin-bottom:10px'><strong>Chrome</strong>: Install <a href='https://chrome.google.com/webstore/detail/singlefile/mpiodijhokgodhhofbcjdecpffjipkle'>SingleFile</a> and enable the option \"Allow access to file URLs\" in the details page of the extension (chrome://extensions/?id=mpiodijhokgodhhofbcjdecpffjipkle).</li>";
234
- pageContent += "<li style='margin-bottom:10px'><strong>Microsoft Edge</strong>: Install <a href='https://microsoftedge.microsoft.com/addons/detail/singlefile/efnbkdcfmcmnhlkaijjjmhjjgladedno'>SingleFile</a> and enable the option \"Allow access to file URLs\" in the details page of the extension (edge://extensions/?id=efnbkdcfmcmnhlkaijjjmhjjgladedno).</li>";
235
- pageContent += "<li><strong>Safari</strong>: Select \"Security > Disable Local File Restrictions\" in the \"Develop > Developer settings\" menu.</li></ul></div>";
231
+ if (!options.extractDataFromPage) {
232
+ pageContent += "<div id=sfz-error-message><strong>Error</strong>: Cannot open the page from the filesystem.";
233
+ pageContent += "<ul style='line-height:20px;'>";
234
+ pageContent += "<li style='margin-bottom:10px'><strong>Chrome</strong>: Install <a href='https://chrome.google.com/webstore/detail/singlefile/mpiodijhokgodhhofbcjdecpffjipkle'>SingleFile</a> and enable the option \"Allow access to file URLs\" in the details page of the extension (chrome://extensions/?id=mpiodijhokgodhhofbcjdecpffjipkle).</li>";
235
+ pageContent += "<li style='margin-bottom:10px'><strong>Microsoft Edge</strong>: Install <a href='https://microsoftedge.microsoft.com/addons/detail/singlefile/efnbkdcfmcmnhlkaijjjmhjjgladedno'>SingleFile</a> and enable the option \"Allow access to file URLs\" in the details page of the extension (edge://extensions/?id=efnbkdcfmcmnhlkaijjjmhjjgladedno).</li>";
236
+ pageContent += "<li><strong>Safari</strong>: Select \"Security > Disable Local File Restrictions\" in the \"Develop > Developer settings\" menu.</li></ul></div>";
237
+ }
236
238
  if (options.insertTextBody) {
237
239
  const doc = (new DOMParser()).parseFromString(pageData.content, "text/html");
238
240
  doc.body.querySelectorAll("style, script, noscript").forEach(element => element.remove());
@@ -300,7 +302,8 @@ function getHTMLStartData(pageData, options) {
300
302
  pageContent += "<meta name=viewport content=" + JSON.stringify(pageData.viewport) + ">";
301
303
  }
302
304
  if (options.insertMetaCSP) {
303
- pageContent += "<meta http-equiv=content-security-policy content=\"default-src 'none'; connect-src 'self' data: blob:; font-src 'self' data: blob:; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline' data: blob:; frame-src 'self' data: blob:; media-src 'self' data: blob:; script-src 'self' 'unsafe-inline' data: blob:; object-src 'self' data: blob:\">";
305
+ const cspContent = "default-src 'none';connect-src 'self' data: blob:;font-src 'self' data: blob:;img-src 'self' data: blob:;style-src 'self' 'unsafe-inline' data: blob:;frame-src 'self' data: blob:;media-src 'self' data: blob:;script-src 'self' 'unsafe-inline' data: blob:;object-src 'self' data: blob:";
306
+ pageContent += `<meta http-equiv=content-security-policy content=${JSON.stringify(cspContent)}>`;
304
307
  }
305
308
  pageContent += "<style>@keyframes display-wait-message{0%{opacity:0}100%{opacity:1}};body{color:transparent};div{color:initial}</style>";
306
309
  pageContent += "<body hidden>";