-
-
Notifications
You must be signed in to change notification settings - Fork 247
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
If an element is added with an ID such as opener
which overlaps a built-in window property, happy-dom
throws an error. (We hit this when someone happened to use opener
as a button ID.)
To Reproduce
Run this in the Node REPL or some other context:
const { Window } = await import('happy-dom');
const window = new Window();
const div = window.document.createElement('div');
div.id = 'opener';
window.document.body.appendChild(div);
The last line throws an error:
Uncaught TypeError: Cannot set property opener of #<Window> which has only a getter
at #addIdentifierToWindow (file:///.../node_modules/happy-dom/lib/nodes/element/Element.js:1161:24)
at [connectedToDocument] (file:///.../node_modules/happy-dom/lib/nodes/element/Element.js:1108:40)
at [connectedToNode] (file:///.../node_modules/happy-dom/lib/nodes/node/Node.js:781:53)
at [connectedToNode] (file:///.../node_modules/happy-dom/lib/nodes/html-element/HTMLElement.js:812:46)
at [appendChild] (file:///.../node_modules/happy-dom/lib/nodes/node/Node.js:405:45)
at [appendChild] (file:///.../node_modules/happy-dom/lib/nodes/element/Element.js:999:62)
at HTMLBodyElement.appendChild (file:///.../node_modules/happy-dom/lib/nodes/node/Node.js:298:48)
Expected behavior
Element is added. Following the browser behavior, it appears that if the ID overlaps a built-in window
property, the step of setting window[elementId]
is skipped (the window property keeps its original value).
Spixmaster
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working