|
|
@@ -23,13 +23,15 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const SELECTED_CONTENT_ATTRIBUTE_NAME = "data-single-file-selected-content";
|
|
|
const SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME = "data-single-file-selected-content-root";
|
|
|
|
|
|
- let Download, DOM, URL;
|
|
|
+ let Download, DOM, URL, sessionId = 0;
|
|
|
|
|
|
function getClass(...args) {
|
|
|
[Download, DOM, URL] = args;
|
|
|
return class {
|
|
|
constructor(options) {
|
|
|
this.options = options;
|
|
|
+ options.sessionId = sessionId;
|
|
|
+ sessionId++;
|
|
|
this.SELECTED_CONTENT_ATTRIBUTE_NAME = SELECTED_CONTENT_ATTRIBUTE_NAME;
|
|
|
this.SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME = SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME;
|
|
|
}
|
|
|
@@ -113,7 +115,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
this.processor.resolveHrefs();
|
|
|
this.processor.replaceCanvasElements();
|
|
|
if (this.options.removeHiddenElements) {
|
|
|
- this.processor.removeHiddenElements();
|
|
|
+ this.processor.removeHiddenElements(this.options.sessionId);
|
|
|
}
|
|
|
const initializationPromises = [this.processor.inlineStylesheets(true), this.processor.linkStylesheets(), this.processor.attributeStyles(true)];
|
|
|
if (!this.options.removeFrames) {
|
|
|
@@ -390,8 +392,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
this.stats.set("discarded", "cssRules", removedRules.discarded);
|
|
|
}
|
|
|
|
|
|
- removeHiddenElements() {
|
|
|
- const hiddenElements = this.doc.querySelectorAll("[" + DOM.removedContentAttributeName() + "]");
|
|
|
+ removeHiddenElements(sessionId) {
|
|
|
+ const hiddenElements = this.doc.querySelectorAll("[" + DOM.removedContentAttributeName(sessionId) + "]");
|
|
|
this.stats.set("discarded", "hiddenElements", hiddenElements.length);
|
|
|
hiddenElements.forEach(element => element.remove());
|
|
|
}
|
|
|
@@ -411,7 +413,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (this.options.displayStats) {
|
|
|
size = DOM.getContentSize(this.doc.documentElement.outerHTML);
|
|
|
}
|
|
|
- DOM.htmlminiProcess(this.doc, { preservedSpaceAttributeName: DOM.preservedSpaceAttributeName() });
|
|
|
+ DOM.htmlminiProcess(this.doc, { preservedSpaceAttributeName: DOM.preservedSpaceAttributeName(this.options.sessionId) });
|
|
|
if (this.options.displayStats) {
|
|
|
this.stats.add("discarded", "htmlBytes", size - DOM.getContentSize(this.doc.documentElement.outerHTML));
|
|
|
}
|
|
|
@@ -509,7 +511,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
await Promise.all(frameElements.map(async frameElement => {
|
|
|
DomProcessorHelper.setFrameEmptySrc(frameElement);
|
|
|
frameElement.setAttribute("sandbox", "");
|
|
|
- const frameWindowId = frameElement.getAttribute(DOM.windowIdAttributeName());
|
|
|
+ const frameWindowId = frameElement.getAttribute(DOM.windowIdAttributeName(this.options.sessionId));
|
|
|
if (frameWindowId) {
|
|
|
const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
|
|
|
if (frameData) {
|
|
|
@@ -535,7 +537,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
this.stats.add("processed", "frames", 1);
|
|
|
await frameData.processor.preparePageData();
|
|
|
const pageData = await frameData.processor.getPageData();
|
|
|
- frameElement.removeAttribute(DOM.windowIdAttributeName());
|
|
|
+ frameElement.removeAttribute(DOM.windowIdAttributeName(this.options.sessionId));
|
|
|
DomProcessorHelper.setFrameContent(frameElement, pageData.content);
|
|
|
this.stats.addAll(pageData);
|
|
|
} else {
|