Commit Graph
10126 Commits
Author SHA1 Message Date
Adrià Arrufat bbb8317bc8 Keep body's height its own
html and body both took the document's extent, which now includes html's
declared height, so `html { height: 100% }` gave an empty body the
viewport's height. Chrome and Firefox give it 0. body now takes its
content or its own declared height, and html keeps the extent. A
document without a body yet also counts html's declared height.
2026-11-21 01:05:06 +01:00
Adrià Arrufat 8d34ce7a1b Size html and body from their declared height
html and body took their height from their content only, so a page with
`html, body { height: 100% }` and nothing but a canvas reported a 5px
body. Compose for Web sizes its canvas from the body, and drew into a
1920x5 bitmap.

The document's extent now grows to a declared root height: html's
percentage is of the viewport, body's of html's declared height. It
only grows, so boxes laid out past a shorter declared height still fit.

canvas and video without a size are 300x150, as iframe already was, and
read their width and height attributes like img and iframe.
2026-11-20 10:40:15 +01:00
Karl Seguin 0eb33c8c90 Merge pull request #4703 from navidemad/feat-media-clock
webapi: give HTMLMediaElement a timeline (duration, media clock, seeking, ended)
2026-11-20 09:48:32 +08:00
Karl Seguin 2807201dca Merge pull request #4708 from navidemad/css-supports-cascade
css: apply the rules of an @supports block
2026-11-20 09:39:13 +08:00
Karl Seguin f3e3025523 skip timing sensitive tests on chrome 2026-11-20 09:17:43 +08:00
Karl Seguin 587f3dcdce Merge pull request #4719 from lightpanda-io/selector-never-matches
perf: discard selectors that can never match
2026-11-20 09:03:36 +08:00
Karl Seguin 1fefe2a8a6 Simplify media clock
There's now a single clock that gets re-used. Worse case, our timing is off.
I think that's worth the simplification.
2026-11-20 08:54:11 +08:00
Karl Seguin 3f3c4edad2 add comment, restore original wait-selector behavior 2026-11-20 07:56:31 +08:00
Karl Seguin 7b12a5ef6f perf: discard selectors that can never match
CSS parser now flags selectors that can never match (because we don't support
them, e.g something with a :hover). These can now optionally be discarded at
parse time.
2026-11-20 07:42:07 +08:00
Karl Seguin 5869a0ba60 dev: improve how pseudo selectors are printed
This is only used when we debug. Previously it would print "where(...). Now it
expands it.
2026-11-20 07:26:55 +08:00
Karl Seguin 0dfe31752d Merge pull request #4690 from lightpanda-io/stream-cancel-tee
webapi: ReadableStream cancel handling
2026-11-20 07:17:05 +08:00
Karl Seguin 72e0b25154 Merge pull request #4711 from lightpanda-io/mem-attribute-clone
mem: reduce memory cost of cloning attributes
2026-11-20 07:16:44 +08:00
Karl Seguin 0db90bb458 Merge pull request #4714 from lightpanda-io/handleError-non-generic
chore: make Caller's handleError non-generic
2026-11-20 07:15:57 +08:00
Karl Seguin 042a3f1a4d Merge pull request #4716 from lightpanda-io/pseudo-where-bucket
perf: better :where bucketing
2026-11-20 07:15:16 +08:00
Karl Seguin 87d19c62b4 Merge pull request #4691 from lightpanda-io/mem-semantic-tree
mem: reduce memory cost of semantic tree
2026-11-20 07:14:35 +08:00
Karl Seguin d7a93a2bf4 Merge pull request #4718 from lightpanda-io/shrink-selector-size
mem: shrink selector size
2026-11-20 07:14:15 +08:00
Karl Seguin ee98918604 Merge pull request #4713 from lightpanda-io/identity-map-allocator
mem: Move identity map allocator from arena to gpa
2026-11-20 07:12:51 +08:00
Karl Seguin f7526d97ed mem: shrink selector size
Rework Selector so that it goes from 32 -> 24, and Segment goes from 24 -> 16.
This is the same type of optimization we do else where: a slice converted to
an explicit length and ptr.

The goal here isn't memory savings. It's shrinking them so that we can add to
them without making it bigger (follow up PR).
2026-11-19 20:39:33 +08:00
Karl Seguin d1abfaa17d perf: better :where bucketing
StyleManager currently unwraps simple :where(X) selectors, keeping the zero
specificity but bucketing on X. Anything more complicated ended up in .other.

Any :where that isn't a list (:where(a, b)) can actually be keyed by its
right-most compound without being unwrapped. Moving things out of .other is
always a win.

A list can't because it can match either. I explored splitting the list, so that
:where(a, b) creates two separate selector: :where(a)  and  :where(b), which
is exactly how we treat non-:where lists. But across a bunch of site, this is
an uncommon pattern.
2026-11-19 20:05:34 +08:00
Adrià Arrufat f08ae4d561 Merge pull request #4699 from lightpanda-io/script-async-evaluate
script: make page.evaluate return a promise
2026-11-19 10:25:49 +01:00
Adrià Arrufat 55d670f61e script: sync the lp store as a per-key diff
Each evaluate wrote its page's whole lp object back to the session
store, dropping every key the page didn't have. With evaluates in
flight on several pages, the last to finish undid what the others
stored, and a second evaluate on the same page reset what the first had
written but not yet synced.

The postlude now reports only what the page changed since its last
sync, and the prelude carries the page's unsynced changes over the
fresh copy of the store.

The overlap test counts evaluates in flight instead of timing them.
2026-11-19 09:44:10 +01:00
Karl Seguin 4a09048c9e identity cleanup on error 2026-11-19 16:37:11 +08:00
Karl Seguin 00293c2714 resolve on closed cancel 2026-11-19 16:28:20 +08:00
Karl Seguin c00e7f93e9 chore: make Caller's handleError non-generic
We create 3285 version of this function (and growing), and everything it needs
to be non-generic can easily be supplied by the callers.

Hard to measure accurately, but this saves ~1sec of debug build time.
2026-11-19 12:51:58 +08:00
Karl Seguin b1372d37b5 mem: Move identity map allocator from arena to gpa
On pages that return _a lot_ of zig instances to v8, the arena-backed identity
map 'leaks' roughly half of it's memory (previous allocations). While most pages
don't typically hold that many objects, we've seen cases where they do,
typically related to DOMRect / intersection / boundingRects.

In our own performance scenarios, the identity map peaks at ~14MB, with roughly
half of that wasted.

I think there are more specific solutions we can pick for DOMRect and a few
similar types, but this is a simpler, more general quick memory win.
2026-11-19 12:42:56 +08:00
Karl Seguin 5aa574a65b mem: reduce memory cost of cloning attributes
When canonical names were added (#2901), they were stored on the frame and thus
a clone had to dupe those values (as the clone might be another frame). At some
point, they became owned by the page, so the cloning is no longer needed.

How much this saves depends on how much cloning a site does. Over all of our
performance scenarios, this was the single biggest memory allocation that we
easily control (because those tests clone a lot).
2026-11-19 11:36:06 +08:00
Karl Seguin 180ac95c22 mem: reduce memory cost of semantic tree
1. The node registry is deferred until we're sure the node will make it into
the output. Looking at the HTML5 one page layout, that cuts the number of nodes
from 672k to 314k. Cutting tens of MB from peak memory

2. Dumps which go through SemanticTree can now skip node registration
altogether. A node_id counter is used to keep things working.
2026-11-19 09:15:07 +08:00
Karl Seguin 88b533b5cf include getContentQuads in the invisible -> error path 2026-11-19 09:13:06 +08:00
Navid EMAD 507b3dcaff Fix box models for display:none and expose the live select label over CDP 2026-11-19 09:13:06 +08:00
Karl Seguin 469b73ce25 Merge pull request #4698 from lightpanda-io/script-get-cookies
script: add page.getCookies()
2026-11-19 09:03:32 +08:00
Karl Seguin 5c1eee048e Merge pull request #4696 from lightpanda-io/bidi-addPreloadScript
bidi: add script.addPreloadScript and script.removePreloadScript
2026-11-19 08:02:43 +08:00
Karl Seguin 6abc5c9e0d remove expired cookies before printing 2026-11-19 07:59:36 +08:00
Karl Seguin f1eb1bfb39 silence tests, fix script order in test 2026-11-19 07:43:14 +08:00
Karl Seguin 5ede72542c clamp scrollheight using boxHeight 2026-11-19 07:11:10 +08:00
Karl Seguin 5478d03b3c layout: min-height and max-height support 2026-11-19 07:11:10 +08:00
Karl Seguin 4d2aa3312b Improve lengths
negative max/min width -> 0

optimized calc_rem when rem is the only relative term

truncate coefficient since we're dealing with f16
2026-11-19 07:08:30 +08:00
Karl Seguin e7573feba8 layout: support more length units
Adds support for em and rem units. Adds limited support for calc(...). Because
we can't store 2 relative terms (e.g. 100% - 2rem) without needing more memory,
we convert one of those units (rem) to pixels on read based on the
DEFAULT_FONT_SIZE.

If we ever add better (i.e. not just inline) support for font-size, this might
need to be revisited.
2026-11-19 07:08:25 +08:00
Karl Seguin a2c00ff764 Merge pull request #4689 from lightpanda-io/hit-z-index-main
hit test: positioned boxes are above, negative z-index below
2026-11-19 07:01:42 +08:00
Adrià Arrufat 5af9febfab Merge pull request #4678 from lightpanda-io/mcp-tools-allowlist
mcp: add --tools to expose only the named tools
2026-11-18 23:25:53 +01:00
Navid EMAD e0692c4890 css: apply the rules of an @supports block
The rules inside an `@supports` block never reached the cascade:
StyleManager.addStoredRules had arms for `@media` and `@layer`, and
`@supports` fell into the catch-all. The block is already parsed into child
rules and css/supports.zig already evaluates a <supports-condition> for
CSS.supports(), so evaluate the prelude and, when it holds, add the children
where the block is, through the helper the other grouping rules use.

A bare declaration is not a condition in an at-rule prelude, so the rule
path skips the retry CSS.supports() does for one.

Closes #4705
2026-11-18 18:24:47 +01:00
Navid EMAD bc5604b577 webapi: tie the media clock to its frame, leave unread sources alone
The clock's finalizer left the element pointing at a freed task: an element
that outlived its frame (held by a parent's script) wrote through it on the
next seek. The finalizer now stops the clock and clears the pointer, and the
element's tasks run on its own frame's scheduler, not the caller's.

A source whose duration isn't read no longer changes networkState, nor
resets the element when its src changes: only an element with a timeline is
reset. A data: URL is only decoded when its type is a WAV one.

An element playing out its timeline pauses when it leaves its document.
currentTime and playbackRate reject non-finite values with a TypeError
instead of taking the NaN the bridge coerces them to, which sought to the end.
2026-11-18 18:14:37 +01:00
Navid EMAD 40b0b0a140 webapi: give HTMLMediaElement a timeline
duration was always NaN, currentTime never advanced, ended and seeking were
hardcoded to false, and no metadata, timeupdate, seeking or ended event was
ever fired. Nothing is decoded or played, but a media clock is enough for a
page that drives its own player from these.

Resource selection reads the duration of the src attribute, or of the first
<source> child it can read: a WAV file in a data: URL, for now. The element
then fires the metadata events, currentTime follows the scheduler's clock at
playbackRate while it plays, a task fires timeupdate and runs the end-of-media
steps (loop, or pause + ended), and assigning currentTime seeks. A source
whose duration can't be read keeps the faked playback it had.

Closes #4702
2026-11-18 17:43:45 +01:00
Adrià Arrufat fe976f5c80 script: give page.goto the argument diagnostics of a tool call
startGoto bypasses call, so a bad argument rejected with a bare
"navigation failed". It now goes through the same prepareArgs pass as
startEvaluate and rejects with the diagnostic, before the receiver's
page is replaced.
2026-11-18 16:32:17 +01:00
Adrià Arrufat 6b29ae0e35 script: make page.evaluate return a promise
page.evaluate blocked the script until the page-side promise settled,
so several requests only overlapped when batched inside one evaluate.

It now returns a promise, like page.goto. A page promise that is still
pending is left to the driver loop, which ticks every waiting page
together, so Promise.all over several evaluates overlaps their fetches
and timers. The evaluate tool itself still waits, for MCP and the
agent.

Breaking: a script that uses the result without await now gets a
promise. The recorder and the script guide emit await page.evaluate.
2026-11-18 15:35:10 +01:00
Adrià Arrufat b747f457dd script: add page.getCookies()
Scripts had no way to see the cookie jar: document.cookie through
page.evaluate hides HttpOnly cookies, and the getCookies tool was kept
off the page object because script methods were exactly the recorded
tools.

Tool.isScriptable() now decides what a page carries: the recorded tools
plus getCookies, which stays out of recordings. Called from a script it
returns an array of cookie objects in the --cookie-jar shape; the MCP
and agent tool keep their text lines.
2026-11-18 15:30:21 +01:00
Pierre Tachoire 565fff97cb bidi: accept "default" in addPreloadScript userContexts while another user context is active 2026-11-18 13:46:02 +01:00
Pierre Tachoire 1aa9eaf8ea js: add Value.toFunction, use it for the bidi function casts 2026-11-18 11:57:31 +01:00
Pierre Tachoire bc4bc64ec9 bidi: store user context id inline 2026-11-18 11:57:30 +01:00
Pierre Tachoire 79b03adc57 bidi: add script.addPreloadScript and script.removePreloadScript 2026-11-18 11:57:30 +01:00
Adrià Arrufat b0e5986a54 mcp: complete --tools with the tool names
The option's type is a bit set, a packed struct whose one field is
`mask`, so completion offered that. An option can now name its
`choices`, and --tools gives the tool names.

The help leads with "Can be passed multiple times", like the other
list options, and keeps the comma-separated form.
2026-11-18 10:55:00 +01:00