Commit Graph

4838 Commits

Author SHA1 Message Date
Karl Seguin
50b126b402 fix cachelayer hit path 2026-05-13 07:14:44 +08:00
Karl Seguin
edc3d836d1 explicit track if transfer is queued for correct cleanup 2026-05-12 20:32:40 +08:00
Karl Seguin
caa47d50b2 fix build 2026-05-12 19:30:46 +08:00
Karl Seguin
73241dd1f7 don't mutate hashmap while iterating (in teardown) 2026-05-12 19:26:25 +08:00
Karl Seguin
5e0976bbd6 fix use-after-free on robotslayer shutdown 2026-05-12 19:26:24 +08:00
Karl Seguin
7869cbb68c Delay Page destruction to avoid UAF
Encapsulate resource ownership in a HttpClient.Owner
2026-05-12 19:26:24 +08:00
Karl Seguin
2dc3b4682b abort frame-specific transfers 2026-05-12 19:26:24 +08:00
Karl Seguin
82a4fc752b HttpClient Improvements
1 - Track owner of a request (for simpler / more accurate abort (TBD))

2 - Create Transfer upfront, make everything work on Transfer (not Request)
    This helps remove ambiguity about cleanup and simplifies layers. For example
    Robots request is just another normal request, not a special case. This gives
    everything a stable address (the *Transfer which can be looked up by id)
2026-05-12 19:26:24 +08:00
Karl Seguin
09747cf951 Enable ImageData and OffscreenCanvasRenderingContext2D on Worker
These are currently reachable in Worker via the OffscreenCanvas, so when used
they crash. WPT /html/canvas/offscreen/2d.conformance.requirements.basics.worker.html
2026-05-12 17:42:37 +08:00
Karl Seguin
c8dc9d8938 Merge pull request #2428 from lightpanda-io/revert-pr-2394
Revert "Merge pull request #2394
2026-05-12 15:33:54 +08:00
Karl Seguin
8bede8684e Revert "Merge pull request #2394 from lightpanda-io/custom_element_reactions"
This reverts commit 5c7097b6a0, reversing
changes made to 235f1cd9bc.
2026-05-12 15:16:40 +08:00
Karl Seguin
e9b2aa4946 Merge pull request #2426 from lightpanda-io/feat/cdp-disable-iframes
Feat/cdp disable iframes
2026-05-12 13:16:16 +08:00
Karl Seguin
cdfabf7953 Minor tweaks
Remove repeating description/comment of flag.

Change CDP lp command to be a general configuration endpoint.
2026-05-12 12:56:33 +08:00
Karl Seguin
353cf45b38 Merge pull request #2425 from lightpanda-io/subcommand_help
Add per-subcommand help via `help` or `--help` argument
2026-05-12 10:52:44 +08:00
Karl Seguin
5c7097b6a0 Merge pull request #2394 from lightpanda-io/custom_element_reactions
CustomElement Reactions
2026-05-12 10:49:46 +08:00
Karl Seguin
235f1cd9bc Merge pull request #2386 from lightpanda-io/improve_elementFromPoint
optimize elementFromPoint
2026-05-12 10:49:30 +08:00
Karl Seguin
58e7e72459 Merge pull request #2409 from lightpanda-io/abortsignal_any
add AbortSignal.any static + AbortSignal reason can be a DOMException
2026-05-12 10:49:09 +08:00
Karl Seguin
f705d8b8e9 Merge pull request #2412 from lightpanda-io/events
Improve events
2026-05-12 10:48:56 +08:00
Karl Seguin
45b1cc4762 Merge pull request #2411 from lightpanda-io/htmlcollection_string_indexer
Fix HTMLCollection
2026-05-12 10:48:44 +08:00
Francis Bouvier
31ef5246bc Add per-subcommand help via help or --help argument
`lightpanda <subcommand> help`, `lightpanda <subcommand> --help`
now print only the relevant subcommand options plus common options,
instead of the full text.

`lightpanda help <subcommand>` is also supported
(and that's what use internally).
2026-05-11 22:16:52 +02:00
Karl Seguin
3733abbf8a Merge pull request #2413 from lightpanda-io/small_dom_fixes
Various small DOM fixes, WPT driven
2026-05-11 21:58:01 +08:00
Karl Seguin
fe729f8b1f CustomElement Reactions
While this PR touches a lot of files, and isn't trivial, many of the changes
are either:
1 - removing guards added in previous PRs, e.g.
    https://github.com/lightpanda-io/browser/pull/1969
    https://github.com/lightpanda-io/browser/pull/2172
    https://github.com/lightpanda-io/browser/pull/2313
    https://github.com/lightpanda-io/browser/pull/2366

2 - Adding the `.ce_reactions = true` flag to various WebAPIs

CustomElements have callbacks, e.g. connectedCallback. Also, many WebAPI calls
are implemented as a series of mutations, e.g. appendChild = remove from current
+ append to new.

These two things interact in an important way: when should callbacks execute?
Before this PR, we were invoking callbacks at each individual step. This is
(a) technically wrong and (b) breaks a lot of assumptions (the reason the above
4 PRs were needed to fix bugs).

This PR adds a `_ce_reactions` queue to the frame. And, instead of invoking
callbacks, we "enqueue" the reaction. At various boundaries, a scope is created
the DOM manipulation is done, and then we pop the scope, invoking all queued
reactions.
2026-05-11 21:50:24 +08:00
Karl Seguin
082994c331 Allow HTML Tests to set a timeout
Change worker timeout to 8seconds. This test can be slow on a slow CI with
TSAN enabled.
2026-05-11 21:30:25 +08:00
Karl Seguin
6fa1fe12a5 Merge pull request #2235 from lightpanda-io/nikneym/cli-script-eval
`fetch`: add support for `--inject-script` and `--inject-script-file` options
2026-05-11 21:24:50 +08:00
Karl Seguin
8bea867e5f Merge pull request #2406 from navidemad/parser-defer-rawtext-merge
parser: defer raw-text merge to bound memory growth
2026-05-11 21:05:39 +08:00
Karl Seguin
258003ca90 ArrayListUnmanaged (deprecated name) -> ArrayList 2026-05-11 20:42:11 +08:00
Navid EMAD
a470f6b686 parser: lift merge buffer onto Parser and lazy-buffer single-chunk runs
Addresses follow-up review from karlseguin on #2406.

The pending-text merge buffer is now a single ArrayList on the Parser,
reused across runs via clearRetainingCapacity. In the streaming-parser
case (Document.write), parser.arena is the page-lifetime frame.arena, so
the previous per-PendingText buf.deinit was a no-op and growth artifacts
accumulated. With one shared buffer, total dead memory is bounded to one
peak-run-sized allocation regardless of how many text runs the parse
contains.

Single-chunk text runs no longer touch the buffer. The first chunk lives
only on CData._data via createTextNode; the buffer is seeded from
text_node.getData().str() only when a second chunk arrives at the same
parent and last_child. flushPendingText is a no-op when the buffer is
empty. Restores the common-case allocation count to 1 (matching main),
vs 3 in the previous PR head.

Benchmark deltas (ReleaseFast, peak RSS, 5-run median):
- 10K-paragraph synthetic page: 39 MB -> 37 MB
- 20K single-chunk script synthetic: 56 MB -> 54 MB
- 100 x 48 KB multi-chunk scripts: within noise (~46 MB)
- apple.com US iPhone live page: within JS-driven noise (~92 MB)

Refs #2397
2026-05-11 14:36:40 +02:00
Karl Seguin
cfcfe4ee29 Merge pull request #2417 from lightpanda-io/nikneym/dummy-set-resource-timing-buffer-size
`Performance`: add dummy `setResourceTimingBufferSize`
2026-05-11 20:31:17 +08:00
Halil Durak
5faaf3dc15 --inject-script: testable injected scripts 2026-05-11 15:24:28 +03:00
Halil Durak
3c7c08f822 --inject-script: don't error out if script execution fails 2026-05-11 15:24:08 +03:00
Halil Durak
19401dc950 Config: update --inject-script documentation 2026-05-11 15:15:36 +03:00
Halil Durak
d97081d71f --inject-script: execute injected scripts if encountered <head> tag
This now backs itself against html5ever to find <head>; the spec explicitly bans double-appearance of <head> tag and html5ever is aware of it.
2026-05-11 15:15:36 +03:00
Halil Durak
60d721caa2 Config: increase read file size for --inject-script-file 2026-05-11 15:15:36 +03:00
Halil Durak
246f91d1f8 --inject-script: prefer splice bytes into <head> directly 2026-05-11 15:15:35 +03:00
Halil Durak
c566d0c41c introduce --inject-script and --inject-script-file
* Prefer `--inject-*` prefix.
* Support injecting multiple scripts (also allows using both variants together).
* Instead of executing scripts in JS context, actually insert them to `<head>` for correct dump output.
2026-05-11 15:15:35 +03:00
Halil Durak
39f12a5669 fetch: add support for --script option
Allows passing a JS file as an arg to be executed alongside other scripts.
2026-05-11 15:15:35 +03:00
Halil Durak
9d7eee211a Performance: fix zig fmt fail 2026-05-11 15:12:44 +03:00
Halil Durak
556cbc1c9f Update src/browser/webapi/Performance.zig
Co-authored-by: Karl Seguin <karlseguin@users.noreply.github.com>
2026-05-11 15:09:06 +03:00
Halil Durak
bcc82bff4a Performance: add dummy setResourceTimingBufferSize 2026-05-11 14:47:40 +03:00
Halil Durak
4e4e68e51c HTMLLinkElement: update tests 2026-05-11 14:40:40 +03:00
Halil Durak
3c8c849947 HTMLLinkElement: crossOrigin -> crossorigin for attributes 2026-05-11 14:40:26 +03:00
Halil Durak
20c7bc14d2 HTMLLinkElement: update tests 2026-05-11 14:35:41 +03:00
Halil Durak
55a42fe5c6 HTMLLinkElement: add media getter/setter 2026-05-11 14:35:30 +03:00
Navid EMAD
60219e69e9 parser: address review findings for raw-text merge
- Flush pending text in _removeFromParentCallback and
  _reparentChildrenCallback. Without these, html5ever can detach or
  reparent the pending text node mid-parse and a later flush would write
  accumulated bytes onto a node no longer in the tree (or to the wrong
  parent).

- Streaming.done now nulls self.handle right after html5ever_finish,
  before flushPendingText. If the flush errors the handle is already
  cleared, so dropping the Streaming can't double-free.

- Document.close uses a defer to clear _script_created_parser even when
  done() returns an error. Document.write's parser-panic path now
  attempts a final flush before dropping the streaming parser, so
  whatever bytes html5ever fed before the panic still land on their
  text node.

- raw_text_chunked.html: larger raw-text bodies and exact byte counts
  per element. Catches future deferred-merge regressions that drop or
  duplicate a chunk; the memory bound itself is verified out-of-band
  via the live reproducer in the PR description.

Refs #2397
2026-05-11 13:22:29 +02:00
Navid EMAD
15101f12e4 parser: defer raw-text merge to bound memory growth
Frame.appendNew did String.concat(arena, [existing, txt]) every time
html5ever flushed a script-data/rawtext chunk on a '<' token, allocating
O(N) on the page-lifetime arena per chunk. Total bytes ~= N^2/(2*c). On
apple.com US iPhone pages a 347 KB inline JSON literal with embedded
HTML strings ballooned the parse to 3.5 GB peak RSS.

Move the merge into the parser. Same-parent text chunks accumulate in a
std.ArrayListUnmanaged on the per-parse arena; one String.dupe lands the
final value on the frame arena. Flush points are the natural ends of a
text run: a non-text child appended, a foster/before-sibling insertion,
the parent element popping, or the parse call returning.

Frame.appendNew now takes *Node directly; it had no non-parser callers.
Streaming.done returns !void to propagate the final flush.

Refs #2397
2026-05-11 13:22:29 +02:00
Pierre Tachoire
d2151b6ffd Merge pull request #2305 from navidemad/feat/xpath-1.0-evaluator
xpath: implement XPath 1.0 (Document.evaluate, XPathResult, DOM.performSearch)
2026-05-11 10:01:28 +02:00
Karl Seguin
c16c15bedf Various small DOM fixes, WPT driven
1. Implement document.adoptNode (we were removing from the existing document,
   but not adding to the new document)

2. Document.url should use the document's frame, falling back to the execution
   frame

3. Move HTMLDocument.location to Document.location

4. DOMImplementation.createDocument uses a more appropriate default namespace
   (xml -> null)

5. Map querySelector functions to DOMException-safe errors. The Selector returns
   specific errors, but for the DOM apis (document.querySelector,
   df.querySelectorAll, elem.matches, etc...) these largely all map to
   SyntaxError
2026-05-11 14:29:47 +08:00
Karl Seguin
8d5eef44c8 Improve events
1 - Expose various event types for Workers
2 - Listen to the removed listener flag in more places. We delay removing the
    listener (to keep the list intact) via a flag, but need to consider that
    flag in all places, e.g. when checking for duplicates when adding a listener
3 - Enforce passive flag. We have this flag, but weren't using it to block
    calls to preventDefault returnValue (which a passive listener should not
    call)
2026-05-11 12:34:52 +08:00
Karl Seguin
a5aa302e65 Fix HTMLCollection
For any unknown string keys, it should return error.NotHandled (which tells
v8 that we did not service the request).
2026-05-11 11:42:04 +08:00
Karl Seguin
c90e47646e add AbortSignal.any static + AbortSignal reason can be a DOMException 2026-05-11 11:38:06 +08:00