Commit Graph

4521 Commits

Author SHA1 Message Date
Karl Seguin
6e729131ed Mutex for Isolate.Terminate
Improvement to https://github.com/lightpanda-io/browser/pull/2246

In that PR, the check for `v8__Isolate__IsExecutionTerminating` guarded
runMicrotasks from running when the execution was terminated, but what if
termination happens immediately after?  This adds a mutex to ensure that the
isolate cannot be terminated while microtasks are being processed.
2026-04-27 11:10:38 +08:00
Karl Seguin
a578f4d6ad Merge pull request #2246 from lightpanda-io/terminate
Adds --terminate-ms command line argument + ctrl-c improvements in fetch
2026-04-27 08:57:45 +08:00
Karl Seguin
e1e9a0d78c Merge pull request #2244 from navidemad/fix/get-element-by-id-from-node-recovery
Fix Frame.getElementByIdFromNode to recover from removed_ids
2026-04-27 08:46:05 +08:00
Karl Seguin
b3257754e0 Merge pull request #2245 from lightpanda-io/navigate_load_arena
Use an arena from the ArenaPool for the main page
2026-04-26 08:25:55 +08:00
Karl Seguin
fc636d4e36 Merge pull request #2247 from lightpanda-io/small_fixes
Various small fixes
2026-04-26 08:25:41 +08:00
Adrià Arrufat
093555b374 browser: hint v8 gc during long waits
Runner._wait can iterate for the full opts.ms budget (up to 30s in
fetch, longer in agent tool-use loops). V8 was only nudged to GC on
session/page teardown (Browser.deinit, Page.deinit), so a page that
stays alive while running heavy JS accumulates wrappers and
external-ref'd Zig allocations V8 has no reason to drop. Fire
memoryPressureNotification(.moderate) once per second from the wait
loop.
2026-04-25 08:19:49 +02:00
Karl Seguin
8509b112b8 Various small fixes
Extracted from https://github.com/lightpanda-io/browser/pull/2242
2026-04-25 13:22:41 +08:00
Karl Seguin
12c2efb811 Adds --terminate-ms command line argument + ctrl-c improvements in fetch
The main.zig path for `fetch` now captures the *Browser so that
browser.env.terminate() can be called. This is a bit more complex than the serve
path because the Browser owns the Isolate and can't be moved from one thread to
another.

With main having access to the browser, two things are now possible:
1 - We can support a --terminate-ms flag (https://github.com/lightpanda-io/browser/issues/2206)
2 - ctrl-c can correctly stop blocked JavaScript processes

1 is implemented via setitimer to set a timer for SIGALRM, avoiding the need to
add another "watcher" thread, or putting a timer in Network.run.
2026-04-25 12:34:06 +08:00
Karl Seguin
d02674f365 Use an arena from the ArenaPool for the main page
Was previously using page.arena, but there's no reason to hold this beyond the
point where the page is parsed, and the page can live for quite some time after
the initial load.
2026-04-25 10:49:27 +08:00
Karl Seguin
25cec9bd82 Merge pull request #2233 from lightpanda-io/custom_elements
Custom elements
2026-04-25 10:12:09 +08:00
Navid EMAD
3761d2a32f Fix querySelector('#id') vs getElementById('id') disagreement
Frame.getElementByIdFromNode is the selector engine's fast path for
`#id` queries. It only consulted `_elements_by_id`, while
Document.getElementById and ShadowRoot.getElementById both fall back
to `_removed_ids` + TreeWalker to recover a surviving duplicate after
the first has been removed.

The two APIs could disagree after DOM manipulation that removes a
duplicate-ID element (e.g. Turbo Drive's PageRenderer.replaceBody
doing innerHTML + replaceWith):

  document.querySelector('#page-title')  => null
  document.getElementById('page-title')  => <h1>

Dispatch to the existing canonical getElementById on the scope
(ShadowRoot or Document) instead of keeping a third, map-only copy
of the lookup. The two APIs now agree by construction.
2026-04-25 04:04:14 +02:00
Karl Seguin
3cdb7ee91c Merge pull request #2239 from lightpanda-io/test_only_use_after_free
Fix a test-only use-after-free
2026-04-25 07:41:17 +08:00
Karl Seguin
8a08d1b407 Fix a test-only use-after-free
Only surfaced if an individual test was ran. When running multiple tests, the
bucket reuse of the underlying arena hides the issue.
2026-04-24 21:51:50 +08:00
Pierre Tachoire
b2b1302fa2 Merge pull request #2234 from lightpanda-io/empty_redirect_user_after_free
Fix a use-after-free on an empty (and invalid) location
2026-04-24 14:52:07 +02:00
Nikolay Govorov
999f57b729 Remove timeout flag 2026-04-24 12:40:25 +01:00
Karl Seguin
87a99749b7 Use TCP_KEEPALIVE instead of TCP_KEEPIDLE on MacOS
See: https://github.com/nginx/nginx/issues/336
2026-04-24 12:40:24 +01:00
Nikolay Govorov
c7d004fefb Setup timeout via tcp keepalive 2026-04-24 12:40:21 +01:00
Adrià Arrufat
46f8fc5a13 Merge pull request #2236 from lightpanda-io/fix/optional-positional-args
cli: allow optional positional arguments in command builder
2026-04-24 13:36:38 +02:00
Pierre Tachoire
5b9c05753c Merge pull request #2232 from lightpanda-io/axtree-nodeid-string 2026-04-24 13:22:37 +02:00
Adrià Arrufat
6a65801527 cli: allow optional positional arguments in command builder 2026-04-24 13:08:40 +02:00
Karl Seguin
7b50dff956 Fix a user-after-free on an empty (and invalid) empty location
Improves WPT: /fetch/api/redirect/redirect-empty-location.any.html
2026-04-24 18:31:45 +08:00
Karl Seguin
802ae55cc1 Update WebDriver to use Page
Don't use pre-built snapshot for wpt action (the snapshot needs the WebDriver
added, which is not normally added). Instead, rely on runtime snapshot creation
(this just adds a bit of startup time and peak memory, neither or which should
be an issue for WPT runs).
2026-04-24 17:33:16 +08:00
Karl Seguin
757c70b6db Add adoptedCallback for CustomElements
Fired when elements are moved from one document to another. I don't think this
is really used much, but it helps pass a number of WPT cases.

This required tweaking insertAdjacentHTML as it was creating a full document
and trigger spurious callbacks in the new code. A DocumentFragment is now used
instead.
2026-04-24 17:26:39 +08:00
Pierre Tachoire
f63b8ae004 cdp: AXNodeId is a string per spec
AXNodeId is defined as string in CDP spec.
This this a difference with DOM.NodeId which is an int.

https://chromedevtools.github.io/devtools-protocol/tot/Accessibility/#type-AXNodeId
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#type-NodeId
2026-04-24 11:24:16 +02:00
Karl Seguin
2c4179f1ad Support direct instantiation of custom element
Support `new MyElement()` syntax to create custom element. The implementation
for this is pretty straightforward, but it depends on:
https://github.com/lightpanda-io/zig-v8-fork/pull/173.

Also modify the `attributeChangedCallback` and pass a missing parameter: the
namespace. Currently, we pass `null`, but this is less likely to cause issues
than not passing anything.
2026-04-24 16:48:24 +08:00
Karl Seguin
3f0cc7a0df Merge pull request #2227 from lightpanda-io/better_errdefer_cleanups
Improve various errdefer flows
2026-04-24 16:37:28 +08:00
Karl Seguin
ae24343dce Merge pull request #2220 from lightpanda-io/performance_observer_functions
Add getEntriesByType and getEntriesByName to PerformanceObserver entr…
2026-04-24 16:35:32 +08:00
Karl Seguin
b15a40adc4 Merge pull request #2224 from lightpanda-io/console_own_properties
Define v8 functions directly on console instance.
2026-04-24 16:34:46 +08:00
Karl Seguin
402981fc55 Improve various errdefer flows
This possibly addresses some release overflows that could happen during various
failures. For example, if Frame.init fails during a navigation event, this will
make sure to remove the frame from the parent list preventing a double-free
on the frame.
2026-04-24 11:04:17 +08:00
Karl Seguin
a18b5deed1 Merge pull request #2222 from lightpanda-io/flaky_test_maybe_fix
try to make a flaky test more robust
2026-04-24 06:50:17 +08:00
Karl Seguin
813c7d2aa0 Merge pull request #2219 from lightpanda-io/unused_imports
Remove unused imports
2026-04-24 06:49:58 +08:00
Nikolay Govorov
bf72f57f65 Merge pull request #2223 from lightpanda-io/wp/mrdimidium/fix-canadaca-problem
Fix canada.ca problem
2026-04-23 14:07:23 +01:00
Karl Seguin
f450bddcc3 Define v8 functions directly on console instance.
functions should be defined directly on the window.console (and window.CSS)
instances. This is necessary for being able to iterate their "own" properties.
businessinsider.com has code that proxies console via such an iterator (through
Object.entries(console)). This commit allows types to declare that they own
their properties (as opposed to the prototype).

Also fixed HTMLDocument.location. This was using Document._location, but that
field wasn't always set. The new code removes the _location field and changes
the getter to get window._location. (Also an issue on businessinsider.com)
2026-04-23 20:16:28 +08:00
Halil Durak
c8d45af112 Merge pull request #2221 from lightpanda-io/cli_default_serve 2026-04-23 14:54:23 +03:00
Nikolay Govorov
c964604c7a Fix canada.ca problem 2026-04-23 12:15:57 +01:00
Karl Seguin
f883084406 try to make a flaky test more robust 2026-04-23 18:08:42 +08:00
Karl Seguin
6ca9208260 Default command 'serve' for backwards compatibility 2026-04-23 17:31:25 +08:00
Karl Seguin
f15561d531 Add getEntriesByType and getEntriesByName to PerformanceObserver entry list
Seen on dropbox.com
2026-04-23 17:25:38 +08:00
Karl Seguin
859a41ab4e Adds navigator.userAgentData
This API isn't supported by FireFox (yet), so it isn't a huge priority, but I
did notice that its used across many Google properties. It uses the same value
as Sec-Ch-Ua (https://github.com/lightpanda-io/browser/pull/2100) to provide
consistent data.

Smaller changes:
1 - Allow `OffscreenCanvas` to be used with Worker (noticed this error too)
2 - Don't like JS execution errors at "error" level for "load" and
    "DOMContentLoaded". "error" should be reserved for things we can fix and
    should never be triggered from invalid a bug in JavaScript.
2026-04-23 16:24:42 +08:00
Karl Seguin
0a8f4ff75f Remove unused imports
As a general rule, I keep `std` if its there and unused, mostly for debug.print
debugging.
2026-04-23 16:21:56 +08:00
Halil Durak
7aca1732fe Merge pull request #2098 from lightpanda-io/nikneym/cli-parser 2026-04-23 11:17:44 +03:00
Karl Seguin
4fdf04972e zig fmt 2026-04-23 15:48:15 +08:00
Karl Seguin
550fb58f3f Introduce Page (container)
Follow up to https://github.com/lightpanda-io/browser/pull/2200

This change is actually pretty mundane, but a bunch of files that used to
take a *Session (e.g. every WebAPI releaseRef and deinit) now take a *Page.

This aims to separate the 2 lifetimes currently managed by Session by moving
the "Page" lifetime to a dedicated container: Page. Ultimately, the goal is to
remove the 1-page-per-session limit of the current design. Not to explicitly
support multiple pages per session (though, that's more possible now), but
in order to better emulate Chrome where, during a navigation event, the old and
new page both exist.
2026-04-23 15:48:13 +08:00
Karl Seguin
553b32b3b8 Merge pull request #2217 from lightpanda-io/css_insert_rule_index_clamp
Clamp insert index
2026-04-23 15:39:16 +08:00
Karl Seguin
3d052794d5 Merge pull request #2216 from lightpanda-io/cdp_audit_placeholder
Add placeholder handlers for Audit enable/disable CDP methods
2026-04-23 15:39:01 +08:00
Karl Seguin
15ab2379e3 Merge pull request #2215 from lightpanda-io/set_body
Add setter for document.body
2026-04-23 15:38:48 +08:00
Karl Seguin
2c1abb4500 Merge pull request #2208 from lightpanda-io/worker_apis
More Worker APIs
2026-04-23 15:37:51 +08:00
Karl Seguin
e68dd2b284 Clamp insert index
Because we don't fully process CSS, indexes that code expect might be out of
bounds. The specific case comes from https://github.com/lightpanda-io/browser/issues/2214
which uses fullcalender library. This library uses a @font-face which we do not
process and thus end up with incorrect indexes. As a quick workaround aligned
with previous fixes for these types of cases (and what the original issue
recommended), we simply clamp the index.
2026-04-23 11:23:37 +08:00
Karl Seguin
73320e163d Add placeholder handlers for Audit enable/disable CDP methods
Might help with: https://github.com/lightpanda-io/browser/issues/2177

I say "might" because there are a 2 more methods in Audit which I haven't
implemented. This is just the most basic placeholder for now.
2026-04-23 09:19:49 +08:00
Karl Seguin
338e53460a Add setter for document.body
Fixes: https://github.com/lightpanda-io/browser/issues/2213
2026-04-23 09:15:00 +08:00