From 16dcf3e9e07d551300d2576da976498074d62aed Mon Sep 17 00:00:00 2001 From: David Ortner Date: Mon, 17 Jul 2023 15:02:10 +0200 Subject: [PATCH 1/2] #992@patch: Fixes problem where HTMLIFrameElement fails to load page in some frameworks. The problem is most likely that the Document.defaultView property is overridden somehow. --- .../src/nodes/html-iframe-element/HTMLIFrameUtility.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/happy-dom/src/nodes/html-iframe-element/HTMLIFrameUtility.ts b/packages/happy-dom/src/nodes/html-iframe-element/HTMLIFrameUtility.ts index d3c0a4e81..d1de26c6d 100644 --- a/packages/happy-dom/src/nodes/html-iframe-element/HTMLIFrameUtility.ts +++ b/packages/happy-dom/src/nodes/html-iframe-element/HTMLIFrameUtility.ts @@ -23,7 +23,7 @@ export default class HTMLIFrameUtility { const src = element.src; if (src) { - const contentWindow = new (element.ownerDocument.defaultView.constructor)({ + const contentWindow = new Window({ url: src, settings: { ...element.ownerDocument.defaultView.happyDOM.settings From 560b4eddaafa47af22c415816aa46b539a7a0819 Mon Sep 17 00:00:00 2001 From: David Ortner Date: Mon, 17 Jul 2023 15:27:42 +0200 Subject: [PATCH 2/2] #992@patch: Fixes problem where HTMLIFrameElement fails to load page in some frameworks. The problem is most likely that the Document.defaultView property is overridden somehow. --- packages/happy-dom/src/nodes/document/Document.ts | 3 +++ .../src/nodes/html-iframe-element/HTMLIFrameUtility.ts | 4 ++-- packages/happy-dom/src/window/Window.ts | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts index 31c8b7e56..2a81b653c 100644 --- a/packages/happy-dom/src/nodes/document/Document.ts +++ b/packages/happy-dom/src/nodes/document/Document.ts @@ -56,6 +56,7 @@ const PROCESSING_INSTRUCTION_TARGET_REGEXP = /^[a-z][a-z0-9-]+$/; */ export default class Document extends Node implements IDocument { public static _defaultView: IWindow = null; + public static _windowClass: {} | null = null; public nodeType = Node.DOCUMENT_NODE; public adoptedStyleSheets: CSSStyleSheet[] = []; public implementation: DOMImplementation; @@ -63,6 +64,7 @@ export default class Document extends Node implements IDocument { public readonly readyState = DocumentReadyStateEnum.interactive; public readonly isConnected: boolean = true; public readonly defaultView: IWindow; + public readonly _windowClass: {} | null = null; public readonly _readyStateManager: DocumentReadyStateManager; public _activeElement: IHTMLElement = null; @@ -197,6 +199,7 @@ export default class Document extends Node implements IDocument { this.defaultView = (this.constructor)._defaultView; this.implementation = new DOMImplementation(this); + this._windowClass = (this.constructor)._windowClass; this._readyStateManager = new DocumentReadyStateManager(this.defaultView); this._rootNode = this; diff --git a/packages/happy-dom/src/nodes/html-iframe-element/HTMLIFrameUtility.ts b/packages/happy-dom/src/nodes/html-iframe-element/HTMLIFrameUtility.ts index d1de26c6d..e3a6eeaa1 100644 --- a/packages/happy-dom/src/nodes/html-iframe-element/HTMLIFrameUtility.ts +++ b/packages/happy-dom/src/nodes/html-iframe-element/HTMLIFrameUtility.ts @@ -2,7 +2,6 @@ import { URL } from 'url'; import Event from '../../event/Event.js'; import ErrorEvent from '../../event/events/ErrorEvent.js'; import IWindow from '../../window/IWindow.js'; -import Window from '../../window/Window.js'; import IFrameCrossOriginWindow from './IFrameCrossOriginWindow.js'; import HTMLIFrameElement from './HTMLIFrameElement.js'; @@ -23,7 +22,8 @@ export default class HTMLIFrameUtility { const src = element.src; if (src) { - const contentWindow = new Window({ + // To avoid circular dependency, we use a reference to the window class instead of importing it. + const contentWindow = new element.ownerDocument['_windowClass']({ url: src, settings: { ...element.ownerDocument.defaultView.happyDOM.settings diff --git a/packages/happy-dom/src/window/Window.ts b/packages/happy-dom/src/window/Window.ts index bc00b21d0..cb46c68e5 100644 --- a/packages/happy-dom/src/window/Window.ts +++ b/packages/happy-dom/src/window/Window.ts @@ -519,6 +519,7 @@ export default class Window extends EventTarget implements IWindow { } HTMLDocument._defaultView = this; + HTMLDocument._windowClass = Window; const document = new HTMLDocument();