|
|
@@ -184,7 +184,7 @@ const SingleFileCore = (() => {
|
|
|
return Array.from(this.requests.keys()).length;
|
|
|
}
|
|
|
|
|
|
- async run(beforeListener, afterListener) {
|
|
|
+ async run(beforeListener, afterListener, options) {
|
|
|
const resourceURLs = Array.from(this.requests.keys());
|
|
|
let indexResource = 1, indexAfterResource = 1;
|
|
|
return Promise.all(resourceURLs.map(async resourceURL => {
|
|
|
@@ -193,7 +193,7 @@ const SingleFileCore = (() => {
|
|
|
beforeListener({ index: indexResource, max: resourceURLs.length, url: resourceURL, error });
|
|
|
indexResource = indexResource + 1;
|
|
|
try {
|
|
|
- const dataURI = await Download.getContent(resourceURL, true);
|
|
|
+ const dataURI = await Download.getContent(resourceURL, { asDataURI: true, maxSize: options.maxResourceSize });
|
|
|
resourceRequests.map(resourceRequest => resourceRequest.resolve(dataURI));
|
|
|
} catch (responseError) {
|
|
|
error = responseError;
|
|
|
@@ -221,7 +221,7 @@ const SingleFileCore = (() => {
|
|
|
|
|
|
async loadPage(pageContent) {
|
|
|
if (!pageContent || this.options.saveRawPage) {
|
|
|
- pageContent = await Download.getContent(this.baseURI);
|
|
|
+ pageContent = await Download.getContent(this.baseURI, { asDataURI: false, maxSize: this.options.maxResourceSize });
|
|
|
}
|
|
|
this.dom = DOM.create(pageContent, this.baseURI);
|
|
|
this.DOMParser = this.dom.DOMParser;
|
|
|
@@ -243,7 +243,7 @@ const SingleFileCore = (() => {
|
|
|
}
|
|
|
|
|
|
async retrieveResources(beforeListener, afterListener) {
|
|
|
- await batchRequest.run(beforeListener, afterListener);
|
|
|
+ await batchRequest.run(beforeListener, afterListener, this.options);
|
|
|
}
|
|
|
|
|
|
getPageData() {
|
|
|
@@ -460,7 +460,7 @@ const SingleFileCore = (() => {
|
|
|
|
|
|
async inlineStylesheets(initialization) {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("style")).map(async styleElement => {
|
|
|
- const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(styleElement.textContent, this.baseURI) : await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI);
|
|
|
+ const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(styleElement.textContent, this.baseURI, this.options.maxResourceSize) : await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI);
|
|
|
styleElement.textContent = this.options.compressCSS ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
|
|
|
}));
|
|
|
}
|
|
|
@@ -468,7 +468,7 @@ const SingleFileCore = (() => {
|
|
|
async scripts() {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("script[src]")).map(async scriptElement => {
|
|
|
if (scriptElement.src) {
|
|
|
- const scriptContent = await Download.getContent(scriptElement.src);
|
|
|
+ const scriptContent = await Download.getContent(scriptElement.src, { asDataURI: false, maxSize: this.options.maxResourceSize });
|
|
|
scriptElement.textContent = scriptContent.replace(/<\/script>/gi, "<\\/script>");
|
|
|
}
|
|
|
scriptElement.removeAttribute("src");
|
|
|
@@ -496,7 +496,8 @@ const SingleFileCore = (() => {
|
|
|
compressHTML: this.options.compressHTML,
|
|
|
compressCSS: this.options.compressCSS,
|
|
|
lazyLoadImages: this.options.lazyLoadImages,
|
|
|
- framesData: this.options.framesData
|
|
|
+ framesData: this.options.framesData,
|
|
|
+ maxResourceSize: this.options.maxResourceSize
|
|
|
};
|
|
|
if (frameData.content) {
|
|
|
frameData.processor = new PageProcessor(options);
|
|
|
@@ -563,14 +564,14 @@ const SingleFileCore = (() => {
|
|
|
|
|
|
async attributeStyles(initialization) {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("[style]")).map(async element => {
|
|
|
- const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(element.getAttribute("style"), this.baseURI) : await DomProcessorHelper.processStylesheet(element.getAttribute("style"), this.baseURI);
|
|
|
+ const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(element.getAttribute("style"), this.baseURI, this.options.maxResourceSize) : await DomProcessorHelper.processStylesheet(element.getAttribute("style"), this.baseURI);
|
|
|
element.setAttribute("style", stylesheetContent);
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
async linkStylesheets() {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("link[rel*=stylesheet]")).map(async linkElement => {
|
|
|
- const stylesheetContent = await DomProcessorHelper.resolveLinkStylesheetURLs(linkElement.href, this.baseURI, linkElement.media);
|
|
|
+ const stylesheetContent = await DomProcessorHelper.resolveLinkStylesheetURLs(linkElement.href, this.baseURI, linkElement.media, this.options.maxResourceSize);
|
|
|
const styleElement = this.doc.createElement("style");
|
|
|
styleElement.textContent = this.options.compressCSS ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
|
|
|
linkElement.parentElement.replaceChild(styleElement, linkElement);
|
|
|
@@ -599,7 +600,7 @@ const SingleFileCore = (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static async resolveImportURLs(stylesheetContent, baseURI) {
|
|
|
+ static async resolveImportURLs(stylesheetContent, baseURI, maxResourceSize) {
|
|
|
stylesheetContent = DomUtil.removeCssComments(stylesheetContent);
|
|
|
const imports = DomUtil.getImportFunctions(stylesheetContent);
|
|
|
await Promise.all(imports.map(async cssImport => {
|
|
|
@@ -607,7 +608,7 @@ const SingleFileCore = (() => {
|
|
|
if (match) {
|
|
|
const resourceURL = DomUtil.normalizeURL(match.resourceURL);
|
|
|
if (resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
|
|
|
- let importedStylesheetContent = await Download.getContent(new URL(match.resourceURL, baseURI).href);
|
|
|
+ let importedStylesheetContent = await Download.getContent(new URL(match.resourceURL, baseURI).href, { asDataURI: false, maxSize: maxResourceSize });
|
|
|
importedStylesheetContent = DomUtil.wrapMediaQuery(importedStylesheetContent, match.media);
|
|
|
if (stylesheetContent.indexOf(cssImport) != -1) {
|
|
|
stylesheetContent = stylesheetContent.replace(cssImport, importedStylesheetContent);
|
|
|
@@ -617,7 +618,7 @@ const SingleFileCore = (() => {
|
|
|
}));
|
|
|
stylesheetContent = DomProcessorHelper.resolveStylesheetURLs(stylesheetContent, baseURI);
|
|
|
if (imports.length) {
|
|
|
- return await DomProcessorHelper.resolveImportURLs(stylesheetContent, baseURI);
|
|
|
+ return await DomProcessorHelper.resolveImportURLs(stylesheetContent, baseURI, maxResourceSize);
|
|
|
} else {
|
|
|
return stylesheetContent;
|
|
|
}
|
|
|
@@ -635,11 +636,11 @@ const SingleFileCore = (() => {
|
|
|
return stylesheetContent;
|
|
|
}
|
|
|
|
|
|
- static async resolveLinkStylesheetURLs(resourceURL, baseURI, media) {
|
|
|
+ static async resolveLinkStylesheetURLs(resourceURL, baseURI, media, maxResourceSize) {
|
|
|
resourceURL = DomUtil.normalizeURL(resourceURL);
|
|
|
if (resourceURL && resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
|
|
|
- let stylesheetContent = await Download.getContent(resourceURL);
|
|
|
- stylesheetContent = await DomProcessorHelper.resolveImportURLs(stylesheetContent, resourceURL);
|
|
|
+ let stylesheetContent = await Download.getContent(resourceURL, { asDataURI: false, maxSize: maxResourceSize });
|
|
|
+ stylesheetContent = await DomProcessorHelper.resolveImportURLs(stylesheetContent, resourceURL, maxResourceSize);
|
|
|
stylesheetContent = DomUtil.wrapMediaQuery(stylesheetContent, media);
|
|
|
return stylesheetContent;
|
|
|
}
|