Custom Elements + Shadow DOM Shim #20

Closed
opened 2026-06-17 14:01:50 +00:00 by Artur · 1 comment
Owner

Goal

Implement customElements.define(), customElements.get(), customElements.whenDefined(), and element.attachShadow().

What to Build

  1. src/custom-elements/shim.ts — CustomElementRegistry class
  2. Register globalThis.customElements in createIsolatedContext
  3. HTMLElement.prototype.attachShadow returns minimal ShadowRoot
  4. ShadowRoot: mode, host, innerHTML, querySelector, appendChild

Tests (110%)

  • customElements is defined
  • customElements.define() registers element
  • customElements.get() returns constructor
  • customElements.whenDefined() resolves
  • element.attachShadow returns ShadowRoot
  • ShadowRoot.mode reflects open/closed
  • ShadowRoot.host returns element
  • element.shadowRoot returns the shadowRoot
  • shadowRoot.querySelector works
  • shadowRoot.querySelectorAll works
  • shadowRoot.appendChild works
  • shadowRoot.innerHTML getter/setter works
  • attachShadow({mode: 'closed'}) hides shadowRoot

Definition of Done

  • CustomElementRegistry with define/get/whenDefined
  • attachShadow returns minimal ShadowRoot
  • All ShadowRoot API methods work
  • Tests pass with 100% line coverage
## Goal Implement customElements.define(), customElements.get(), customElements.whenDefined(), and element.attachShadow(). ## What to Build 1. `src/custom-elements/shim.ts` — CustomElementRegistry class 2. Register globalThis.customElements in createIsolatedContext 3. HTMLElement.prototype.attachShadow returns minimal ShadowRoot 4. ShadowRoot: mode, host, innerHTML, querySelector, appendChild ## Tests (110%) - customElements is defined - customElements.define() registers element - customElements.get() returns constructor - customElements.whenDefined() resolves - element.attachShadow returns ShadowRoot - ShadowRoot.mode reflects open/closed - ShadowRoot.host returns element - element.shadowRoot returns the shadowRoot - shadowRoot.querySelector works - shadowRoot.querySelectorAll works - shadowRoot.appendChild works - shadowRoot.innerHTML getter/setter works - attachShadow({mode: 'closed'}) hides shadowRoot ## Definition of Done - [ ] CustomElementRegistry with define/get/whenDefined - [ ] attachShadow returns minimal ShadowRoot - [ ] All ShadowRoot API methods work - [ ] Tests pass with 100% line coverage
Author
Owner

Custom Elements + Shadow DOM Shim. Implementiert via Happy DOM. Tests: custom-elements.test.ts.

Custom Elements + Shadow DOM Shim. ✅ Implementiert via Happy DOM. Tests: custom-elements.test.ts.
Artur closed this issue 2026-06-18 06:28:05 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
glow-all/true-headless-browser#20
No description provided.