Re: [whatwg/dom] Proposal: DOM APIs in web workers? (Issue #1217)

I want to parse an HTML string in a service worker to multiple [editable and syncable JSON documents](https://lexical.dev/docs/api/modules/lexical_html#generatenodesfromdom) and index them. It's important for the documents to be stored in the service worker so that they can be [synced across different clients](https://tinybase.org/api/synchronizers/) and [persisted](https://tinybase.org/api/persisters/). Then I want to `postMessage` a single document at a time to the main thread for rendering.

Sadly, I'm left with three bad options:
1. Preprocess the HTML documents to JSON and host the JSON. This limits what documents users can ingest and ties me to a JSON schema right away.
2. Include ~50Kb of a [pure JS HTML parser](https://pkg-size.dev/parse5) that's strictly worse than [DOMParser.parseFromString](https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString).
3. Block the UI on the main thread while parsing. Since `HTMLDocument` is NOT [structured clonable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), I'll have to block for longer to parse the HTMLDocument to JSON before doing an extra `postMessage` to the service worker.

> A lot more is needed with regards to step 1-7 of https://whatwg.org/faq#adding-new-features.

I really think only step 7 is left. There are multiple problem statements from 20+ people since [2016](https://github.com/w3c/ServiceWorker/issues/846#issue-141082449) that boil down to https://github.com/whatwg/dom/issues/1217#issuecomment-1660281300.

What browsers want to support parsing HTML from a [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers)? This unlocks offline document mutation, synchronization, and indexing.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1217#issuecomment-2442590348
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1217/2442590348@github.com>

Received on Monday, 28 October 2024 20:44:16 UTC