Commit Graph

4737 Commits

Author SHA1 Message Date
Karl Seguin
2a103fc94a Use Session as a container for cross-frame resources
The introduction of frames means that data is no longer tied to a specific Page
or Context. 255b9a91cc introduced Origins for
v8 values shared across frames of the same origin. The commit highlighted the
lifetime mismatched that we now have with data that can outlive 1 frame. A
specific issue with that commit was the finalizers were still Context-owned.
But like any other piece of data, that isn't right; aside from modules, nothing
should be context-owned.

This commit continues where the last left off and moves finalizers from Context
to Origin. This is done in a separate commit because it introduces significant
changes. Currently, finalizers take a *Page, but that's no longer correct. A
value created in one Page, can outlive the Page. We need another container. I
original thought to use Origin, but that isn't know to CDP/MCP. Instead, I
decide to enhance the Session.

Session is now the owner of the page.arena, the page.factory and the
page.arena_pool. Finalizers are given a *Session which they can use to release
their arena.
2026-03-11 08:44:49 +08:00
Karl Seguin
753391b7e2 Add origins safety cleanup when destroying the context for the root page 2026-03-11 08:43:41 +08:00
Karl Seguin
94ce5edd20 Frames on the same origin share v8 data
Depends on: https://github.com/lightpanda-io/zig-v8-fork/pull/153

In some ways this is an extension of
https://github.com/lightpanda-io/browser/pull/1635 but it has more implications
with respect to correctness.

A js.Context wraps a v8::Context. One of the important thing it adds is the
identity_map so that, given a Zig instance we always return the same v8::Object.

But imagine code running in a frame. This frame has its own Context, and thus
its own identity_map. What happens when that frame does:

```js
window.top.frame_loaded = true;
```

From Zig's point of view, `Window.getTop` will return the correct Zig instance.
It will return the *Window references by the "root" page. When that instance is
passed to the bridge, we'll look for the v8::Object in the Context's
`identity_map` but wont' find it. The mapping exists in the root context
`identity_map`, but not within this frame. So we create a new v8::Object and now
our 1 zig instance has N v8::Objects for every page/frame that tries to access
it.

This breaks cross-frame scripting which should work, at least to some degree,
even when frames are on the same origin.

This commit adds a `js.Origin` which contains the `identity_map`, along with our
other `v8::Global` storage. The `Env` now contains a `*js.Origin` lookup,
mapping an origin string (e.g. lightpanda.io:443) to an *Origin. When a Page's
URL is changed, we call `self.js.setOrigin(new_url)` which will then either get
or create an origin from the Env's origin lookup map.

js.Origin is reference counted so that it remains valid so long as at least 1
frame references them.

There's some special handling for null-origins (i.e. about:blank). At the root,
null origins get a distinct/isolated Origin. For a frame, the parent's origin
is used.

Above, we talked about `identity_map`, but a `js.Context` has 8 other fields
to track v8 values, e.g. `global_objects`, `global_functions`,
`global_values_temp`, etc. These all must be shared by frames on the same
origin. So all of these have also been moved to js.Origin. They've also been
merged so that we now have 3 fields: `identity_map`, `globals` and `temps`.

Finally, when the origin of a context is changed, we set the v8::Context's
SecurityToken (to that origin). This is a key part of how v8 allows cross-
context access.
2026-03-11 08:43:40 +08:00
Nikolay Govorov
3626f70d3e Merge pull request #1759 from lightpanda-io/wp/mrdimidum/net-poll-runtime
Network poll runtime
2026-03-10 23:38:07 +00:00
Nikolay Govorov
24cc24ed50 Fix Robots deinit 2026-03-10 23:28:40 +00:00
Karl Seguin
dd29ba4664 Merge pull request #1767 from egrs/css-value-normalization-gaps
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / zig build release (push) Has been cancelled
wpt / build wpt runner (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
e2e-integration-test / zig build release (push) Has been cancelled
e2e-integration-test / demo-integration-scripts (push) Has been cancelled
extend CSS value normalization to cover more properties
2026-03-11 06:28:34 +08:00
Pierre Tachoire
dd91d28bfa Merge pull request #1761 from lightpanda-io/wp/mrdimidium/c-tsan
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Enable tsan for c libs
2026-03-10 15:33:33 +01:00
Pierre Tachoire
1ebf7460fe Merge pull request #1768 from lightpanda-io/inspector_cleanup
Call `resetContextGroup` on page removal
2026-03-10 15:32:47 +01:00
Pierre Tachoire
8c930e5c33 Merge pull request #1769 from lightpanda-io/form_action
Add Form.action getter/setter
2026-03-10 15:31:34 +01:00
egrs
4fb2f7474c remove incorrect entries from normalization maps
- Remove scale, contain-intrinsic-size, animation-range, text-box-edge
  from isTwoValueShorthand: these have asymmetric or 3-value semantics
  that make "X X" → "X" collapse incorrect.
- Remove line-height from isLengthProperty: bare 0 is the unitless
  number multiplier, not a length (Chrome serializes as "0" not "0px").
- Fix test: background-size "cover cover" is invalid CSS, use "auto auto".
2026-03-10 14:08:28 +01:00
Karl Seguin
5301f79989 Add Form.action getter/setter 2026-03-10 20:58:31 +08:00
egrs
6a7f7fdf15 extend CSS value normalization to cover more properties
Add missing properties to isLengthProperty (0→0px) and
isTwoValueShorthand (duplicate value collapse) maps based
on WPT test failures in css/css-sizing, css/css-align,
css/css-scroll-snap, css/css-logical, and others.

New length properties: scroll-margin/padding-*, column-width,
column-rule-width, grid-column/row-gap, outline, shape-margin,
offset-distance, translate, animation-range-*, block-step-size,
text-decoration-inset, and *-rule-*-inset (CSS Gaps).

New two-value shorthands: scroll-padding-block/inline,
scroll-snap-align, background-size, border-image-repeat,
mask-repeat/size, contain-intrinsic-size, scale, text-box-edge,
animation-range, grid-gap.
2026-03-10 13:53:27 +01:00
Karl Seguin
11fb5f990e Call resetContextGroup on page removal
Calling it here ensures that the inspector gets reset on internal page
navigation. We were seeing intermittent segfaults on a problematic WPT tests
(/encoding/legacy-mb-japanese/euc-jp/) which I believe this solves.

(The tests are still broken. Because we don't support form targets, they cause
the root page to reload in a tight cycle, causing a lot of context creation /
destruction, which I thin was the issue. This commit doesn't fix the broken test
but it hopefully fixes the crash).

Also, clear out the Inspector's default_context when the default context is
destroyed. (This was the first thing I did to try to fix the crash, it didn't
work, but I believe it's correct).
2026-03-10 20:50:58 +08:00
Adrià Arrufat
62f31ea24a Merge pull request #1765 from egrs/lp-get-structured-data
add LP.getStructuredData CDP command
2026-03-10 21:48:18 +09:00
egrs
f4ca5313e6 use std.mem.startsWith, group duplicate property keys into arrays
Address review feedback:
- replace custom startsWith helper with std.mem.startsWith
- writeProperties now groups repeated keys (e.g. multiple og:image)
  into JSON arrays; single-occurrence keys remain strings
- add test for duplicate key serialization
2026-03-10 13:18:25 +01:00
Karl Seguin
dfd90bd564 Merge pull request #1754 from lightpanda-io/css_value_normalization
Apply some normalization to CSS values
2026-03-10 17:36:27 +08:00
Pierre Tachoire
55508eb418 Merge pull request #1763 from lightpanda-io/has_direct_listener
Add a hasDirectListeners to EventManager
2026-03-10 10:28:39 +01:00
Pierre Tachoire
2a4fa4ed6f Merge pull request #1762 from lightpanda-io/xml_get_elements_by_tag_name
Node matching using tag name string comparison on non-HTML nodes
2026-03-10 10:27:47 +01:00
Pierre Tachoire
cf7c9f6372 Merge pull request #1760 from lightpanda-io/response_blob
Add new Response and Request methods
2026-03-10 10:26:16 +01:00
Pierre Tachoire
ec68c3207d Merge pull request #1764 from lightpanda-io/js_val_args
Better support for variadic js.Value parameter (e.g. console.log)
2026-03-10 10:16:27 +01:00
Pierre Tachoire
ecf140f3d6 Merge pull request #1766 from lightpanda-io/screenshot-size
cdp: reszie the screenshot to 1920x1080
2026-03-10 10:15:46 +01:00
Pierre Tachoire
13f73b7b87 Merge pull request #1750 from lightpanda-io/url_set_username_password
Add setters to URL.username and URL.password
2026-03-10 10:15:10 +01:00
Pierre Tachoire
12c5bcd24f cdp: reszie the screenshot to 1920x1080
To be consistent w/ layout size returned
2026-03-10 10:09:53 +01:00
egrs
74f0436ac7 merge main, resolve conflicts with getInteractiveElements 2026-03-10 09:25:12 +01:00
egrs
22d31b1527 add LP.getStructuredData CDP command 2026-03-10 09:19:51 +01:00
Karl Seguin
9f3bca771a Merge pull request #1755 from lightpanda-io/cdp-page-layout-metrics
cdp: add a dummy Page.getLayoutMetrics
2026-03-10 16:16:17 +08:00
Adrià Arrufat
4e16d90a81 Merge pull request #1757 from egrs/lp-get-interactive-elements
add LP.getInteractiveElements CDP command
2026-03-10 17:15:18 +09:00
Pierre Tachoire
d669d5c153 cdp: add a dummy Page.getLayoutMetrics 2026-03-10 08:54:48 +01:00
Karl Seguin
343d985e96 Better support for variadic js.Value parameter (e.g. console.log)
The bridge will prefer to map a Zig array to a JS Array, but in the case of
a []js.Value, it should be willing to map anything into it.
2026-03-10 15:40:18 +08:00
egrs
dc3958356d address review feedback
- TreeWalker.Full instead of FullExcludeSelf so querying a specific
  nodeId evaluates the root element itself
- resolve href to absolute URL via URL.resolve
- isDisabled checks ancestor <fieldset disabled> with legend exemption
- parameter order: allocator before *Page per convention
2026-03-10 08:13:01 +01:00
Karl Seguin
c4e85c3277 Add a hasDirectListeners to EventManager
Allows checking if a direct listener exists, if it doesn't, event creation can
be skipped.

I looked at a couple sites, the benefits of this is small.
Most sites don't seem to trigger that many direct dispatches and when they do,
they seem to have a listener 50-75% of the time.
2026-03-10 14:57:40 +08:00
Karl Seguin
89e46376dc Merge pull request #1752 from lightpanda-io/build-zig-fmt-check
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
build: add code formatting check
2026-03-10 14:04:28 +08:00
Karl Seguin
8eeb34dba8 Node matching using tag name string comparison on non-HTML nodes
NodeLive (used by, e.g. getElementsByTagName) needs to revert to the non-
optimized string-comparison for non-HTML tags.

This should help fix https://github.com/lightpanda-io/browser/issues/1214
2026-03-10 13:42:54 +08:00
Nikolay Govorov
7171305972 Enable tsan for c libs 2026-03-10 03:16:50 +00:00
Nikolay Govorov
2b0c223425 Some code-review fixes 2026-03-10 03:00:55 +00:00
Nikolay Govorov
8f960ab0f7 Uses posix pipe for shutdown network runtime 2026-03-10 03:00:53 +00:00
Nikolay Govorov
60350efa10 Only one listener in network.Runtime 2026-03-10 03:00:52 +00:00
Nikolay Govorov
687f577562 Move accept loop to common runtime 2026-03-10 03:00:50 +00:00
Nikolay Govorov
8e59ce9e9f Prepare global NetworkRuntime module 2026-03-10 03:00:47 +00:00
Karl Seguin
33d75354a2 Add new Response and Request methods
-Response.blob
-Response.clone
-Request.blob
-Request.text
-Request.json
-Request.arrayBuffer
-Request.bytes
-Request.clone
2026-03-10 09:05:06 +08:00
Karl Seguin
0e4a65efb7 Merge pull request #1758 from lightpanda-io/http-auth-challenge
http: handle auth challenge for non-proxy auth
2026-03-10 06:39:14 +08:00
Karl Seguin
b88134cf04 Merge pull request #1756 from lightpanda-io/cdp-screenshot
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / zig build release (push) Has been cancelled
wpt / build wpt runner (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
e2e-integration-test / zig build release (push) Has been cancelled
e2e-integration-test / demo-integration-scripts (push) Has been cancelled
cdp: add dummy page.captureScreenshot
2026-03-10 06:37:33 +08:00
Karl Seguin
2aaa212dbc Merge pull request #1753 from lightpanda-io/document_applets
document.applets should always return an empty collection
2026-03-10 06:35:23 +08:00
Karl Seguin
1e37990938 Merge pull request #1741 from lightpanda-io/DOMParser_invalid_xml
Throw exception, as expected, on empty input to DOMParser.parseFromSt…
2026-03-10 06:32:48 +08:00
egrs
a417c73bf7 add LP.getInteractiveElements CDP command
Returns a structured list of all interactive elements on a page:
buttons, links, inputs, ARIA widgets, contenteditable regions, and
elements with event listeners. Includes accessible names, roles,
listener types, and key attributes.

Event listener introspection (both addEventListener and inline
handlers) is unique to LP — no other browser exposes this to
automation code.
2026-03-09 19:46:12 +01:00
Pierre Tachoire
37c34351ee http: handle auth challenge for non-proxy auth 2026-03-09 19:23:36 +01:00
Pierre Tachoire
8672232ee2 cdp: add dummy page.captureScreenshot 2026-03-09 17:38:57 +01:00
Karl Seguin
3ad10ff8d0 Add support for normalization anchor-size css value
vibed this. Seems esoteric, but it helps over 1000 WPT cases pass in
/css/css-anchor-position/anchor-size-parse-valid.html
2026-03-09 18:25:01 +08:00
Karl Seguin
183643547b document.applets should always return an empty collection
Add a new .empty mode to HTMLCollection.

Fixes WPT /shadow-dom/leaktests/html-collection.html
2026-03-09 18:06:22 +08:00
Adrià Arrufat
5568340b9a build: add code formatting check 2026-03-09 18:48:38 +09:00