Skip to content

Commit

Permalink
Merge pull request capricorn86#995 from capricorn86/task/992-typeerro…
Browse files Browse the repository at this point in the history
…r-cannot-read-properties-of-undefined-reading-write

capricorn86#992@patch: Fixes problem where HTMLIFrameElement fails to load page …
  • Loading branch information
capricorn86 authored Jul 17, 2023
2 parents 7b33345 + 5db52c9 commit b928ce0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/happy-dom/src/nodes/document/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ 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;
public readonly children: IHTMLCollection<IElement> = new HTMLCollection<IElement>();
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;

Expand Down Expand Up @@ -197,6 +199,7 @@ export default class Document extends Node implements IDocument {
this.defaultView = (<typeof Document>this.constructor)._defaultView;
this.implementation = new DOMImplementation(this);

this._windowClass = (<typeof Document>this.constructor)._windowClass;
this._readyStateManager = new DocumentReadyStateManager(this.defaultView);
this._rootNode = this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -23,7 +22,8 @@ export default class HTMLIFrameUtility {
const src = element.src;

if (src) {
const contentWindow = new (<typeof Window>element.ownerDocument.defaultView.constructor)({
// To avoid circular dependency, we use a reference to the window class instead of importing it.
const contentWindow = <IWindow>new element.ownerDocument['_windowClass']({
url: src,
settings: {
...element.ownerDocument.defaultView.happyDOM.settings
Expand Down
1 change: 1 addition & 0 deletions packages/happy-dom/src/window/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ export default class Window extends EventTarget implements IWindow {
}

HTMLDocument._defaultView = this;
HTMLDocument._windowClass = Window;

const document = new HTMLDocument();

Expand Down

0 comments on commit b928ce0

Please sign in to comment.