|
|
@@ -205,6 +205,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
// ------------
|
|
|
const ESCAPED_FRAGMENT = "_escaped_fragment_=";
|
|
|
const EMPTY_DATA_URI = "data:base64,";
|
|
|
+ const WIN_ID_ATTRIBUTE_NAME = "data-frame-tree-win-id";
|
|
|
|
|
|
const batchRequest = new BatchRequest();
|
|
|
|
|
|
@@ -424,30 +425,33 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
|
|
|
async frames(initialization) {
|
|
|
const frameElements = Array.from(this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"));
|
|
|
- await Promise.all(frameElements.map(async (frameElement, frameIndex) => {
|
|
|
- const frameWindowId = (this.options.windowId || "0") + "." + frameIndex;
|
|
|
- const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
|
|
|
- DomProcessorHelper.setFrameEmptySrc(frameElement);
|
|
|
- frameElement.setAttribute("sandbox", "");
|
|
|
- if (frameData) {
|
|
|
- if (initialization) {
|
|
|
- const options = Object.create(this.options);
|
|
|
- options.insertSingleFileComment = false;
|
|
|
- options.insertFaviconLink = false;
|
|
|
- options.url = frameData.baseURI;
|
|
|
- options.windowId = frameWindowId;
|
|
|
- if (frameData.content) {
|
|
|
- options.content = frameData.content;
|
|
|
- frameData.processor = new PageProcessor(options);
|
|
|
- frameData.frameElement = frameElement;
|
|
|
- await frameData.processor.loadPage();
|
|
|
- return frameData.processor.initialize();
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (frameData.processor) {
|
|
|
- await frameData.processor.preparePageData();
|
|
|
- const pageData = await frameData.processor.getPageData();
|
|
|
- DomProcessorHelper.setFrameContent(frameElement, pageData.content);
|
|
|
+ await Promise.all(frameElements.map(async (frameElement) => {
|
|
|
+ const frameWindowId = frameElement.getAttribute(WIN_ID_ATTRIBUTE_NAME);
|
|
|
+ if (frameWindowId) {
|
|
|
+ const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
|
|
|
+ DomProcessorHelper.setFrameEmptySrc(frameElement);
|
|
|
+ frameElement.setAttribute("sandbox", "");
|
|
|
+ if (frameData) {
|
|
|
+ if (initialization) {
|
|
|
+ const options = Object.create(this.options);
|
|
|
+ options.insertSingleFileComment = false;
|
|
|
+ options.insertFaviconLink = false;
|
|
|
+ options.url = frameData.baseURI;
|
|
|
+ options.windowId = frameWindowId;
|
|
|
+ if (frameData.content) {
|
|
|
+ options.content = frameData.content;
|
|
|
+ frameData.processor = new PageProcessor(options);
|
|
|
+ frameData.frameElement = frameElement;
|
|
|
+ await frameData.processor.loadPage();
|
|
|
+ return frameData.processor.initialize();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (frameData.processor) {
|
|
|
+ await frameData.processor.preparePageData();
|
|
|
+ const pageData = await frameData.processor.getPageData();
|
|
|
+ frameElement.removeAttribute(WIN_ID_ATTRIBUTE_NAME);
|
|
|
+ DomProcessorHelper.setFrameContent(frameElement, pageData.content);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|