Commit Graph

3600 Commits

Author SHA1 Message Date
Adrià Arrufat
e0f0b9f210 SemanticTree: use AXRole enum for interactive role check 2026-03-06 16:26:08 +09:00
Adrià Arrufat
f2832447d4 SemanticTree: optimize tag and role filtering
* Refactored tag ignoring logic to use the el.getTag() enum switch
  instead of string comparisons, improving performance and safety.
* Replaced string comparisons for interactive roles with
  std.StaticStringMap.
* Renamed internal dumpNode method to dump for brevity.
2026-03-06 16:12:57 +09:00
Adrià Arrufat
471ba5baf6 String: refactor isAllWhitespace into String 2026-03-06 15:52:53 +09:00
Adrià Arrufat
248851701f Refactor: move SemanticTree to core and expose via MCP tools 2026-03-06 15:44:03 +09:00
Adrià Arrufat
0f46277b1f CDP: implement LP.getSemanticTree for native semantic DOM extraction 2026-03-06 15:29:32 +09:00
Karl Seguin
679e703754 Release KeyboardEvent if it isn't used 2026-03-06 09:12:58 +08:00
Karl Seguin
7322f90af4 Merge pull request #1722 from lightpanda-io/fetch_wait_for_background
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
Run the message loop more!
2026-03-06 08:22:41 +08:00
Adrià Arrufat
320aaf0e33 TreeWalker: remove unused methods
They were introduced in:

- https://github.com/lightpanda-io/browser/pull/1718
2026-03-05 21:51:22 +09:00
Karl Seguin
5fdf1cb2d1 Run the message loop more!
In https://github.com/lightpanda-io/browser/pull/1651 we started to run the
message loop a lot more. One specific case we added for `fetch` was when there
were no scheduled tasks or HTTP, but background tasks, we'd wait for them to
complete.

One case we missed though is if WE do have a schedule tasks, but it's too far
into the future. In that case, we would just exit. This now adds the same logic
for checking and waiting for any background tasks in that case.
2026-03-05 18:51:34 +08:00
Pierre Tachoire
c64500dd85 update ref counting for new ReadableStream usages 2026-03-05 11:47:48 +01:00
Pierre Tachoire
812ad3f49e add reference counting for ReadableStream 2026-03-05 11:47:48 +01:00
Pierre Tachoire
8e8a1a7541 use a pool arena with ReadableStream 2026-03-05 11:47:47 +01:00
Karl Seguin
4863b3df6e Merge pull request #1721 from lightpanda-io/fix_mcp_unintialized_memory
Ensure that mcp.Server is correctly initialized
2026-03-05 17:11:57 +08:00
Karl Seguin
768c3a533b Simplify navigation logic.
Must of the complexity in the previous commit had to do with the fact that
about:blank is processed synchronously, meaning that we could process a
scheduled navigation -> page.navigate -> scheduled navigation:

```
let iframe = document.createElement('iframe');
iframe.addEventListner('load', () => {
  iframe.src = "about:blank";
});
```

This is an infinite loop which is going to be a problem no mater what, but there
are different degrees of problems this can cause, e.g. looping forever vs use-
after-free or other undefined behavior.

The new approach does 2 passes through scheduled navigations, first processing
"asynchronous" navigation (anything not "about:blank"), then processing
synchronous navigation ("about:blank"). The main advantage is that if the
synchronous navigation causes more synchronous navigation, it won't be
processed until the next tick. PLUS, we can detect about:blank that loads
about:blank and stop it (which might not be to spec, but seems right to do
nonetheless). This 2-pass approach removes the need for a couple of checks and
makes everything else simpler.
2026-03-05 17:06:23 +08:00
Karl Seguin
3dea554e9e Ensure that mcp.Server is correctly initialized
It relies on default field values, e.g. for mutex: std.Thread.Mutex = .{}, but
doesn't initialize the structure, just the pointer on the heap resulting in a
crash.
2026-03-05 16:32:25 +08:00
Karl Seguin
9c7ecf221e Improve frame sub-navigation
This makes frame sub-navigation "work" for all page navigations (click, form
submit, location.top...) as well as setting the iframe.src.

Fixes at least 2 WPT crashes.

BUT, the implementation still isn't 100% correct, with two known issues:

1. Navigation currently happens in the context where it's called, not the
   context of the frame. So if Page1 accesses Frame1 and causes it to navigate,
   e.g. f1.contentDocument.querySelector('#link').click(), it's Page1 that will
   be navigated, since the JS is being executed in the Page1 context.
   This should be relatively easy to fix.

2. There are particularly complicated cases in WPT where a frame is navigated
   inside of its own load, creating an endless loop. There's some partial
   support for this as-is, but it doesn't work correctly and it currently is
   defensive and likely will not continue to navigate. This is particularly true
   when sub-navigation is done to about:blank within the frame's on load event.
   (Which is probably not a real concern, but an issue for some WPT tests)

Although it shares a lot with the original navigation code, there are many more
edge cases here, possibly due to being developed along side WPT tests. The
source of most of the complexity is the synchronous handling of "about:blank"
in page.navigate, which can result in a scheduled navigation synchronously
causing more scheduled navigation. (Specifically because
`self.documentIsComplete();` is called from page.navigate in that case). It
might be worth seeing if something can be done about that, to simplify this new
code (removing the double queue, removing the flag, simplifying pre-existing
schedule checks ,...)
2026-03-05 15:09:39 +08:00
Adrià Arrufat
26db481d46 markdown: refactor content discovery to use TreeWalker 2026-03-05 14:36:15 +09:00
Adrià Arrufat
3256a57230 TreeWalker: add sibling navigation and skipChildren 2026-03-05 14:29:42 +09:00
Adrià Arrufat
a27de38c03 markdown: encode resolved URLs in links and images 2026-03-05 13:57:42 +09:00
Adrià Arrufat
e2f1609116 markdown: use aria-label or title for empty links 2026-03-05 11:27:51 +09:00
Adrià Arrufat
ea66a91a95 markdown: resolve absolute URLs and skip empty links 2026-03-05 10:48:18 +09:00
Karl Seguin
6c5efe6ce0 Merge pull request #1715 from lightpanda-io/cdp-frame-navigate
cdp: don't dispatch executionContextsCleared on frame navigation
2026-03-04 22:02:30 +08:00
Karl Seguin
f0be6675e7 Merge pull request #1714 from lightpanda-io/fix-req-id
cdp: fix req id resolver, they are REQ- not RID-
2026-03-04 21:59:04 +08:00
Pierre Tachoire
6a8174a15c cdp: don't dispatch executionContextsCleared on frame navigation 2026-03-04 14:45:21 +01:00
Pierre Tachoire
40c3f1b618 cdp: fix req id resolver, they are REQ- not RID- 2026-03-04 13:00:16 +01:00
Pierre Tachoire
6dd2dac049 Merge pull request #1704 from lightpanda-io/non-ascii-css-key
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
css: fix crash in consumeName() on UTF-8 multibyte sequences
2026-03-04 12:35:14 +01:00
Karl Seguin
b39bbb557f Merge pull request #1713 from lightpanda-io/dynamic_module_instantiation
Force dynamic module instantiation if not already instantiated
2026-03-04 16:27:06 +08:00
Karl Seguin
f7682cba67 Force dynamic module instantiation if not already instantiated
I couldn't come up with a reproducible case where this was needed, but we're
seeing some crash reports indicate that this is happening.
2026-03-04 16:12:11 +08:00
Pierre Tachoire
f94c07160a Merge pull request #1712 from lightpanda-io/css-selector-quote
Handle commas inside quoted attributes
2026-03-04 09:00:01 +01:00
Karl Seguin
bbe6692580 Merge pull request #1711 from lightpanda-io/iframe_about_blank
iframe handling for src = "about:blank"
2026-03-04 15:56:26 +08:00
Karl Seguin
9266a1c4d9 Merge pull request #1709 from lightpanda-io/expand_event_dispatch_handle_scope
Use a single HandleScope for event dispatch
2026-03-04 15:56:13 +08:00
Pierre Tachoire
220d80f05f Handle commas inside quoted attributes
In CSS selector, commas inside quoted attribute are not selector separators, but part of
the attribute value.
2026-03-04 08:49:33 +01:00
Karl Seguin
9144c909dd Merge pull request #1710 from lightpanda-io/custom_element_clone
Support for clone custom elements that attach them self in their cons…
2026-03-04 15:47:39 +08:00
Karl Seguin
7981fcec84 iframe handling for src = "about:blank"
Don't try to resolve an iframe's source if it's about:blank

Extend the page's handling of about:blank to render an empty document
2026-03-04 15:43:07 +08:00
Pierre Tachoire
71264c56fc Merge pull request #1696 from lightpanda-io/textencoder-stream
Add TextEncoderStream and TextDecoderStream implementation
2026-03-04 07:58:56 +01:00
Karl Seguin
ca0f77bdee Support for clone custom elements that attach them self in their constructor
When we createElement, we assume the element is detached. This is usually true
except for Custom Elements where the constructor can do anything, including
connecting the element. This broken assumption results in cloneNode crashing.
2026-03-04 14:54:34 +08:00
Karl Seguin
fc8b1b8549 Use a single HandleScope for event dispatch
https://github.com/lightpanda-io/browser/pull/1690 narrowed the lifetime of
HandleScopes to once per listener. I think that was just an accident of
refactoring, and not some intentional choice.

The narrower HandleScope lifetime makes it so that when we do run microtask
queue at the end of event dispatching, some locals in the queue may not longer
be valid.

HS1
  HS2
    queueMicrotask(func)
  runMicrotask

In the above flow, `func` is only valid while HS2 is alive, so when we run
the microtask queue in HS1, it is no longer valid.
2026-03-04 11:43:09 +08:00
Karl Seguin
bc8c44f62f Merge pull request #1707 from lightpanda-io/nikneym/details
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
e2e-integration-test / zig build release (push) Has been cancelled
e2e-integration-test / demo-integration-scripts (push) Has been cancelled
Add `HTMLDetailsElement`
2026-03-04 07:44:11 +08:00
Karl Seguin
01fab5c92a Merge pull request #1706 from lightpanda-io/cdp-attach-to-browser
cdp: fix send CDP raw command with Playwright
2026-03-04 07:40:05 +08:00
Karl Seguin
1c07d786a0 Merge pull request #1705 from lightpanda-io/nikneym/track
` Track`: implement kind and constants
2026-03-04 07:34:12 +08:00
Karl Seguin
6f0cd87d1c Merge pull request #1703 from lightpanda-io/client_and_script_manager
Fix a few issues in Client
2026-03-04 07:32:14 +08:00
Karl Seguin
e44308cba2 Merge pull request #1695 from lightpanda-io/iframe_src_nav
Iframe src nav
2026-03-04 07:27:23 +08:00
Karl Seguin
50245c5157 Merge pull request #1667 from lightpanda-io/terminate_isolate
On Client.stop, terminate the isolate
2026-03-04 07:27:10 +08:00
Pierre Tachoire
9ca5188e12 cdp: set consistent target's default
with about:blank for url and empty title.
2026-03-03 17:24:08 +01:00
Pierre Tachoire
e25c33eaa6 Merge pull request #1673 from arrufat/mcp
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
Add Model Context Protocol (MCP) server support
2026-03-03 15:18:34 +01:00
Pierre Tachoire
56cc881ac0 Fcdp: fix attachtToTarget and attachToBrowserTarget resp 2026-03-03 15:01:53 +01:00
Adrià Arrufat
7bddc0a89c mcp: remove search and over tools 2026-03-03 22:50:06 +09:00
Halil Durak
50896bdc9d HTMLDetailsElement: add tests 2026-03-03 15:12:12 +03:00
Halil Durak
8dd4567828 HTMLDetailsElement: implement HTMLDetailsElement 2026-03-03 15:12:02 +03:00
Pierre Tachoire
06ef6d3e6a cdp: attachToTarget must add the session id 2026-03-03 12:58:00 +01:00