wasm-quickjs-dom 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/THIRD-PARTY-NOTICES.md +22 -0
- package/dist/bin.js +0 -0
- package/dist/edge-js-payload.js +1 -1
- package/dist/quickjs.wasm +0 -0
- package/package.json +6 -7
- package/vendor/quickjs/README.md +0 -3
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ dom.close();
|
|
|
15
15
|
|
|
16
16
|
**Good for:** pre-rendering single-page apps to HTML (SEO, OGP, link previews), reading data that a page builds with JavaScript, running DOM code in tests on edge runtimes, and handing a scripted page to an image renderer such as [wasm-html-to-image](https://www.npmjs.com/package/wasm-html-to-image).
|
|
17
17
|
|
|
18
|
-
**Not a browser:** there is no layout of its own, no canvas, no `WebSocket` or `Worker`, and QuickJS is an interpreter, so very heavy pages are slow. See [What works](#what-works-and-what-does-not).
|
|
18
|
+
**Not a browser:** there is no layout of its own, no canvas, no working `WebSocket` or `Worker`, and QuickJS is an interpreter, so very heavy pages are slow. See [What works](#what-works-and-what-does-not).
|
|
19
19
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
@@ -169,9 +169,9 @@ There is no layout inside QuickJS, so `getBoundingClientRect()`, `offsetWidth` a
|
|
|
169
169
|
|
|
170
170
|
**Works:** inline, external, dynamically added and `type="module"` scripts (static `import`s and `import("literal")` are fetched up front); `fetch` and `XMLHttpRequest` (binary safe); timers, `requestAnimationFrame`, promises; `history.pushState`, `localStorage` / `sessionStorage` (in memory), `customElements`, `MutationObserver`, `crypto.getRandomValues` / `randomUUID`; `matchMedia` for the viewport width; `getComputedStyle` (the element's own style plus initial values); `IntersectionObserver` and `ResizeObserver` (each reports once on `observe()`, so lazy content loads). React and Next.js clients hydrate and run their effects.
|
|
171
171
|
|
|
172
|
-
**Does not:** layout (see above), `canvas`, `WebSocket`, `EventSource
|
|
172
|
+
**Does not:** layout (see above), `canvas`, `iframe` content, working `WebSocket`, `EventSource` and `Worker` (they exist and fail like a dead connection: an `error` event, then closed, with a warning in `dom.logs`, so code that handles failure carries on), CSS cascade computation, and anything that needs a real browser engine. A DOM smaller than JSDOM's. If a script throws, the page carries on with what it had; `dom.logs` tells you what went wrong.
|
|
173
173
|
|
|
174
|
-
**Speed:** a page starts in about 3 ms (the first in a process pays about 120 ms). A typical page, including its network, takes a few hundred ms
|
|
174
|
+
**Speed:** a page starts in about 3 ms (the first in a process pays about 120 ms). A typical page, including its network, takes a few hundred ms. HTML is parsed natively and building the DOM from it runs at roughly 1.3 MB/s (a 250 KB page in about 190 ms), so very large pages still take seconds.
|
|
175
175
|
|
|
176
176
|
## Where it runs
|
|
177
177
|
|
|
@@ -209,6 +209,8 @@ Exit code `0` is done, `1` the page could not be loaded (or `-e` threw), `2` wro
|
|
|
209
209
|
|
|
210
210
|
Each page gets its own WebAssembly instance of QuickJS-ng. The browser APIs a bare QuickJS lacks, and linkedom, are compiled to QuickJS bytecode when the package is built; the first page of a process starts that program, and every later page is a copy of that started instance, which is why a page starts in about 3 ms. Nothing is shared between pages. Each gets its own clock origin and `Math.random` seed.
|
|
211
211
|
|
|
212
|
+
HTML (the page itself, and every `innerHTML` the page sets) is tokenized by a C port of htmlparser2 inside the WebAssembly module, which hands linkedom the same calls htmlparser2 would; that is about 2.5 times faster than parsing in the interpreter. Input the port does not reproduce exactly (for example non-ASCII tag names) falls back to htmlparser2 by itself.
|
|
213
|
+
|
|
212
214
|
## For contributors
|
|
213
215
|
|
|
214
216
|
The package builds its own QuickJS: `vendor/quickjs` (QuickJS-ng, unmodified) and `csrc/qjsdom.c` are compiled to a standalone `dist/quickjs.wasm` with Emscripten (`emcc` on `PATH`), and the guest program is compiled to bytecode with that very wasm.
|
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -30,3 +30,25 @@
|
|
|
30
30
|
THE SOFTWARE.
|
|
31
31
|
|
|
32
32
|
- **linkedom** (<https://github.com/WebReflection/linkedom>), ISC, and **web-streams-polyfill** (<https://github.com/MattiasBuelens/web-streams-polyfill>), MIT, are bundled into the guest program `dist/edge-js-payload.js`.
|
|
33
|
+
|
|
34
|
+
- **htmlparser2** (<https://github.com/fb55/htmlparser2>, MIT, copyright Felix Böhm and Chris Winberry) and **entities** (<https://github.com/fb55/entities>, BSD-2-Clause, copyright Felix Böhm). `dist/quickjs.wasm` contains a C port of htmlparser2's HTML tokenizer and parser (`csrc/htmlparse.h`) and the HTML named-entity table of `entities` (`csrc/entity_tree.h`); linkedom's own copy of htmlparser2 is also inside the guest program. The entity table is under:
|
|
35
|
+
|
|
36
|
+
Copyright (c) Felix Böhm
|
|
37
|
+
All rights reserved.
|
|
38
|
+
|
|
39
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
40
|
+
|
|
41
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
42
|
+
|
|
43
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
44
|
+
|
|
45
|
+
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
46
|
+
|
|
47
|
+
The htmlparser2 port is under:
|
|
48
|
+
|
|
49
|
+
Copyright 2010, 2011, Chris Winberry <chris@winberry.net>. All rights reserved.
|
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
51
|
+
|
|
52
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
53
|
+
|
|
54
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/bin.js
CHANGED
|
File without changes
|