we (web engine): Experimental web browser project to understand the limits of Claude

Implement page lifecycle events #162

open opened by pierrelf.com

Description#

Implement the standard page lifecycle events in their correct firing order. These events are critical for web applications that need to initialize on load and clean up on unload.

Requirements#

Event Ordering (page load)#

  1. HTML parsing begins
  2. Synchronous scripts execute as encountered
  3. HTML parsing completes
  4. DOMContentLoaded fires on document (bubbles to window)
  5. Deferred scripts execute
  6. Images, stylesheets, and other subresources finish loading
  7. load event fires on window

Event Ordering (page unload / navigation away)#

  1. beforeunload fires on window — handler can call event.preventDefault() to show a confirmation dialog
  2. pagehide fires on window
  3. unload fires on window
  4. Document is discarded and new navigation proceeds

DOMContentLoaded#

  • Fires when the HTML document has been completely parsed
  • Does not wait for stylesheets, images, or subframes
  • Event type: Event (not CustomEvent)
  • Registered via document.addEventListener('DOMContentLoaded', ...)

load#

  • Fires when the page and ALL dependent resources (images, stylesheets, scripts) have loaded
  • Fires on window, also on individual elements (<img>, <script>, <link>)
  • window.onload and <body onload> are equivalent

beforeunload#

  • Allows page to prompt user before leaving
  • If event.preventDefault() is called or event.returnValue is set, show confirmation
  • Confirmation dialog text is browser-controlled (ignore custom message)

unload#

  • Fires when the document is being unloaded
  • Last chance for cleanup; no new navigations allowed during handler

Acceptance Criteria#

  • DOMContentLoaded fires after HTML parsing completes
  • load fires after all resources are loaded
  • beforeunload fires before navigating away and can cancel navigation
  • unload fires during document teardown
  • Events fire in the correct order
  • document.readyState transitions: loadinginteractivecomplete
  • Unit tests for event ordering and readyState transitions
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mii3wn2fk72g