Commit Graph

4943 Commits

Author SHA1 Message Date
katie-lpd
8c52b8357c Update README.md 2026-03-15 16:33:53 +01:00
Karl Seguin
0243c6b450 Fix issues with blobs
https://github.com/lightpanda-io/browser/pull/1775 made blobs finalizable and
https://github.com/lightpanda-io/browser/pull/1795 made it possible to navigate
from blobs (important for WPT tests). This fixes a number of issues related to
both.

First, weak/strong ref'ing a value now uses the resolved value. When registering
a finalizer, we use the resolved value (the most specific type in the prototype
chain). For this reason, when toggling a weak/strong ref, we have to use the
same resolved value. This solves a segfault where a File is created, but
extended as a Blob (e.g. in createObjectURL).

Next, two issues were fixed when navigating to an invalid blob. First, the frame
is properly removed from the parent list on frame navigation error. Second,
on frame navigation error, we don't stop _all_ other navigations, we just log
the error and move on to the next frame.
2026-03-15 21:03:55 +08:00
Adrià Arrufat
f7071447cb Merge pull request #1834 from evalstate/mcp-ping
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / wba-demo-scripts (push) Has been cancelled
e2e-test / wba-test (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
feat(mcp): add ping request handling
2026-03-15 18:15:51 +09:00
Halil Durak
c038bfafa1 Merge pull request #1772 from lightpanda-io/nikneym/failing-body-onload-tests
Add failing `body.onload` tests
2026-03-15 10:58:39 +03:00
sjhddh
4d60f56e66 test: add test case for fetch throwing TypeError on network errors 2026-03-15 07:26:18 +00:00
sjhddh
56d3cf51e8 test: update empty xml parse error case in domparser.html 2026-03-15 07:25:47 +00:00
sjhddh
3013e3a9e6 fix(net): fetch() should reject with a TypeError on network errors 2026-03-15 07:25:47 +00:00
Navid EMAD
fe9b2e672b fix(test): update tests to match new CDP error handling behavior
processMessage no longer returns Zig errors when dispatchCommand fails —
it sends a CDP error response and continues. Update all expectError calls
to use processMessage + expectSentError instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 05:52:20 +01:00
Karl Seguin
3e9fa4ca47 Fix use-after-free with certain CDP scripts
Origins were introduced to group memory/data that can be owned by multiple
frames (on the same origin). There's a general idea that the initial "opaque"
origin is very transient and should get replaced before any actual JavaScript
is executed (because the real origin is setup as soon as we get the header from
the response, long before we execute any script).

But...with CDP, this guarantee doesn't hold There's nothing stop a CDP script
from executing javascript at any point, including while the main page is still
being loaded. This can result on allocations made on the opaque origin which
is promptly discarded.

To solve this, this commit introduced origin takeover. Rather than just
transferring any data from one origin (the opaque) to the new one and then
deinit' the opaque one (which is what results in user-after-free), the new
origin simply maintains a list of opaque origins it has "taken-over"and is
responsible for freeing it (in its own deinit). This ensures that any allocation
made in the opaque origin remain valid.
2026-03-15 12:00:42 +08:00
Navid EMAD
a2e66f85a1 fix(cdp): don't kill WebSocket on unknown domain/method errors
When a CDP command with an unrecognized domain (e.g. `NonExistent.method`)
was sent, the error response was correctly returned but the connection
died immediately after. This happened because dispatch() re-returned the
error after sending the error response, which propagated up through
processMessage() → handleMessage() where `catch return false` closed
the WebSocket connection.

Now the error is only propagated if sendError itself fails (e.g. broken
pipe). Otherwise dispatch() returns normally and the read loop continues.

Fixes #1843

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 04:36:47 +01:00
Karl Seguin
a9b9cf14c3 Merge pull request #1841 from lightpanda-io/reject_error
Improve ergonomics around rejecting a promise with a proper JS error
2026-03-15 10:19:24 +08:00
Karl Seguin
d4b941cf30 zig fmt 2026-03-15 10:06:20 +08:00
Karl Seguin
4b6bf29b83 Improve ergonomics around rejecting a promise with a proper JS error 2026-03-15 09:55:13 +08:00
Karl Seguin
a8b147dfc0 update v8 2026-03-15 09:24:42 +08:00
Karl Seguin
65627c1296 Move ScriptManager to ArenaPool.
This removes the BufferPool. The BufferPool was per-ScriptManager and only
usable for the response. The ArenaPool is shared across pages and threads, so
can provide much better re-use. Furthermore, the ArenaPool provides an
Allocator, so that a Script's URL or inline content can be owned by the arena/
script itself, rather than the page arena.
2026-03-15 09:18:13 +08:00
Matt Van Horn
3dcdaa0a9b Implement charset detection from first 1024 bytes of HTML
Per the HTML spec, browsers should detect charset from <meta> tags
in the first 1024 bytes of a document when the HTTP Content-Type
header doesn't specify one.

Adds Mime.prescanCharset() which scans for:
- <meta charset="X">
- <meta http-equiv="Content-Type" content="...;charset=X">

Integrates into the page loading flow to set the detected charset
on the Mime when no explicit HTTP charset was provided.

Fixes #531
2026-03-14 14:15:40 -07:00
Matt Van Horn
5bc00045c7 fix: serialize AXValue integer as string per CDP spec
The CDP Accessibility spec defines AXValue.value as always being a
string, but integer values were serialized as JSON numbers. This
breaks CDP clients with strict deserialization (e.g., Rust serde).

Fixes #1822
2026-03-14 14:09:49 -07:00
evalstate
93ea95af24 feat(mcp): add ping request handling 2026-03-14 17:48:29 +00:00
Karl Seguin
f754773bf6 window.postMessage across frames
Depends on https://github.com/lightpanda-io/zig-v8-fork/pull/160

Improves postMessage support, specifically for use across frames. This commit
also addresses a few other issues (identified while implementing this).

1 - Since macrotasks can schedule more macrotasks, we need to check the time-to-
next microtask after all microtasks have completed.

2 - frame's onload callback is triggered from the frame's context, but has to
    execute on the parents contet.
2026-03-14 21:04:50 +08:00
Karl Seguin
42bb2f3c58 Merge pull request #1823 from lightpanda-io/remove_double_free
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / wba-demo-scripts (push) Has been cancelled
e2e-test / wba-test (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
Remove frame double-free on navigate error
2026-03-14 19:36:27 +08:00
hobostay
68337a6989 Fix compilation errors: add missing log import and remove duplicate
- Add missing `const log = @import("../../log.zig");` in network.zig
- Remove duplicate `log` declaration inside setCdpCookie in storage.zig
  (already declared at file scope)

Fixes compilation errors:
- src/cdp/domains/network.zig:124:9: error: use of undeclared identifier 'log'
- src/cdp/domains/storage.zig:135:15: error: local constant shadows declaration of 'log'

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 17:32:48 +08:00
Salman Muin Kayser Chishti
bf6dbedbe4 Upgrade GitHub Actions for Node 24 compatibility
Signed-off-by: Salman Muin Kayser Chishti <13schishti@gmail.com>
2026-03-14 09:11:46 +00:00
sjhddh
a204f40968 fix(dom): return parsererror document on XML parse failure 2026-03-14 08:36:06 +00:00
Karl Seguin
fe3faa0a5a Merge pull request #1825 from sjhddh/fix-tracking-allocator-resize
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / wba-demo-scripts (push) Has been cancelled
e2e-test / wba-test (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
fix: only increment TrackingAllocator reallocation_count on successful resizes
v0.2.6
2026-03-14 15:48:49 +08:00
Karl Seguin
39d5a25258 Merge pull request #1820 from hobostay/fix-tracking-allocator-stats
Fix TrackingAllocator reallocation_count being incremented on failed operations
2026-03-14 15:48:13 +08:00
Karl Seguin
f4044230fd Merge pull request #1824 from sjhddh/fix-option-gettext-leak
fix: resolve memory leak in Option.getText() by using page arena
2026-03-14 15:45:53 +08:00
sjhddh
4d6d8d9a83 fix(test): properly count successful reallocations in TrackingAllocator 2026-03-14 06:57:04 +00:00
sjhddh
c4176a282f fix: resolve memory leak in Option.getText() by using page arena 2026-03-14 06:50:26 +00:00
Karl Seguin
1352839472 Remove frame double-free on navigate error
The explicit deinit isn't needed as here's already an errdefer in play.
2026-03-14 14:02:58 +08:00
Karl Seguin
535128da71 Merge pull request #1814 from lightpanda-io/nikneym/window-onload-alias
Make `body.onload` getter/setter alias to `window.onload`
2026-03-14 13:30:10 +08:00
hobostay
099550dddc Ignore partitionKey in cookie operations to support Puppeteer page.setCookie()
Puppeteer's page.setCookie() internally calls Network.deleteCookies twice
before setting a cookie. The second call includes a partitionKey field for
CHIPS (partitioned cookies), which caused Lightpanda to return NotImplemented.

Since Lightpanda doesn't support partitioned cookies, we now silently ignore
the partitionKey parameter and proceed with the cookie operation based on
name/domain/path matching.

This change affects:
- Network.deleteCookies: no longer rejects requests with partitionKey
- Network.setCookie (via setCdpCookie): no longer rejects cookies with partitionKey

Fixes #1818

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 13:18:42 +08:00
hobostay
7fe26bc966 Fix TrackingAllocator reallocation_count being incremented on failed operations
The reallocation_count counter was being incremented regardless of whether
the resize/remap operations succeeded. This led to inaccurate memory
allocation statistics.

- resize: Only increment when rawResize returns true (success)
- remap: Only increment when rawRemap returns non-null (success)

This fixes the TODO comments that were present in the code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 13:10:11 +08:00
Halil Durak
cc6587d6e5 make body.onload getter/setter alias to window.onload 2026-03-13 18:49:26 +03:00
Halil Durak
8b310ce993 add failing body.onload tests 2026-03-13 17:23:26 +03:00
Karl Seguin
be8ba53263 Merge pull request #1811 from lightpanda-io/script_handling
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / wba-demo-scripts (push) Has been cancelled
e2e-test / wba-test (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
Better script handling.
2026-03-13 21:40:19 +08:00
Pierre Tachoire
043d48d1c7 Merge pull request #1812 from lightpanda-io/longer-sleep
ci: add a longer sleep to wait for node start on wba test
2026-03-13 13:59:03 +01:00
Karl Seguin
e8fe80189b Merge pull request #1808 from lightpanda-io/cdp_startup_frames
Tweak CDP startup messages.
2026-03-13 19:24:14 +08:00
Pierre Tachoire
0e48f317cb ci: add a longer sleep to wait for node start on wba test 2026-03-13 12:22:48 +01:00
Karl Seguin
867745c71d Tweak CDP startup messages.
1 - When Target.setAutoAttach is called, send the `Target.attachedToTarget`
    event before sending the response. This matches Chrome's behavior and
    it stops playwright from thinking there's no target and making extra calls,
    e.g. to Target.attachedToTarget.

2 - Use the same dummy frameId for all startup messages. I'm not sure why we
    have STARTUP-P and STARTUP-B. Using the same frame (a) makes more sense to
    me (b) doesn't break any existing integration tests, and (c) improves this
    scenario: https://github.com/lightpanda-io/browser/issues/1800
2026-03-13 19:07:47 +08:00
Karl Seguin
a1a7919f74 Better script handling.
Dynamic scripts have script.async == true by default (we handled this correctly
in the ScriptManager, but we didn't return the right value when .async was
accessed).

Inline scripts only consider direct children, not the entire tree.

Empty inline scripts are executed at a later time if text is inserted into them
2026-03-13 19:05:23 +08:00
Pierre Tachoire
c3de47de90 Merge pull request #1810 from lightpanda-io/fix_cookie_loading
Ensure valid cookie isn't interpreted as null
2026-03-13 11:26:24 +01:00
Pierre Tachoire
dd35bdfeb4 Merge pull request #1809 from lightpanda-io/fix_flaky_test
Fix a flaky frame test
2026-03-13 10:17:01 +01:00
Karl Seguin
07c3aec34f Ensure valid cookie isn't interpreted as null
Use an explicit type when @ptrCast() is assigned to an optional to ensure the
value isn't interpreted as null.
2026-03-13 17:00:59 +08:00
Karl Seguin
bce3e8f7c6 Fix a flaky frame test
Loading `sub 1.html` has a side effect - it increments window.top..sub1_count).
So it should be used careful. It was being used in `about_blank_renavigate` as
a placeholder which _should_ not get navigated, but there's no strict guarantee
about when it gets canceled.
2026-03-13 15:39:34 +08:00
Pierre Tachoire
ba9777e754 Merge pull request #1609 from lightpanda-io/web-bot-auth
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / wba-demo-scripts (push) Has been cancelled
e2e-test / wba-test (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
Web Bot Auth
2026-03-13 08:31:25 +01:00
Pierre Tachoire
7040801dfa Merge pull request #1790 from lightpanda-io/structuredClone_serializer
Add window.structuredClone
2026-03-13 08:29:49 +01:00
Karl Seguin
4f8a6b62b8 Add window.structuredClone
Depends on https://github.com/lightpanda-io/zig-v8-fork/pull/156

Uses V8::Serializer and V8::Deserializer which handles built-in types, e.g.
regex. But it doesn't handle Zig types by default. This is something we need
to hook in, using the delegate callbacks. Which we can do after.

Meant to replace https://github.com/lightpanda-io/browser/pull/1785
2026-03-13 07:28:33 +08:00
Karl Seguin
d3dad772cf Merge pull request #1806 from lightpanda-io/update_zig_v8_action
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
update action.yml to latest zig-v8
2026-03-13 07:26:18 +08:00
Karl Seguin
944b672fea Merge pull request #1792 from lightpanda-io/Canvas_getImageData
Add dummy getImageData to canvas
2026-03-13 07:23:05 +08:00
Karl Seguin
b1c54aa92d Merge pull request #1795 from lightpanda-io/navigate_blob_url
Allow navigation from a blob URL.
2026-03-13 07:22:50 +08:00