Commit Graph

8347 Commits

Author SHA1 Message Date
Halil Durak
eb6321c61a Document: remove dead Location accessor
The one coming from `Window` is the single source of truth now.
2026-06-11 19:18:21 +03:00
Halil Durak
d9731ad6d7 Location: acquire and release Location references properly 2026-06-11 19:18:21 +03:00
Halil Durak
0761ede5ab Location: track lifetime of Location
This is a requirement because of URL object.
2026-06-11 19:18:20 +03:00
Halil Durak
0c15d289e0 URL: track lifetime of the URL object
This essentially holds a Rust Box; so, we deinitialize it when there are no references left.
2026-06-11 19:18:20 +03:00
Halil Durak
88db71221d URL: update tests
Also fixes an FTP related test we had.
2026-06-11 19:18:20 +03:00
Halil Durak
2a6a098001 Frame: adapt to new URL implementation for Location
Now that URL initialization heap-allocates and calls extern functions, this can't happen in comptime.
2026-06-11 19:18:20 +03:00
Halil Durak
f5b4370505 Location: expect []const u8 (no-sentinel) for URL-related strings 2026-06-11 19:18:19 +03:00
Halil Durak
0942b16595 URL: migrate search getter/setter, setHref and toString 2026-06-11 19:18:19 +03:00
Halil Durak
6dfeabc999 spread new implementation (phase 1)
Will have to come up with a solution for search getter/setter and URLSearchParams still; We've also encountered with a bug in URLSearchParams, a fix for it will also be included in the second phase.
2026-06-11 19:18:19 +03:00
Halil Durak
12b3d2c9f4 bind & implement more rust-url utilities 2026-06-11 19:18:19 +03:00
Halil Durak
3f006bf912 add rust-url dependency and bindings for it 2026-06-11 19:18:18 +03:00
Adrià Arrufat
30c8bcbdd9 mcp: pump browser session during idle periods
Pumps the browser session while waiting for MCP requests to prevent
curl timeouts. Adds an idle polling loop to the request router.
2026-06-11 17:48:24 +02:00
Adrià Arrufat
de7ad43bb9 agent: treat first arg of /save as filename and append .js
Updates `/save` to always treat the first token as the filename,
appending `.js` if missing. Remaining tokens are used as the prompt.
2026-06-11 17:35:15 +02:00
Francis Bouvier
ac34d2f9b7 agent: better instructions not to use evaluate on /save 2026-06-11 14:28:45 +02:00
Francis Bouvier
9ca117a235 agent: improve /save system prompt
Remove redudancy between general instructions and skill-like doc.
+ some others improvements
2026-06-11 14:26:57 +02:00
Navid EMAD
7c1af5762d webapi: run sequential focus navigation on Tab
A synthetic Tab delivered via Input.dispatchKeyEvent did not move
document.activeElement. Two gaps in Frame.zig caused this: handleKeydown
(the keydown default-action handler) had no Tab branch, and triggerKeyboard
dropped the keydown entirely when nothing was focused — it read the raw
_active_element field, which is null until an element is explicitly focused.
The first Tab on a page therefore went nowhere, and keyboard focus traversal
was impossible over CDP.

Dispatch the keydown to the effective active element (getActiveElement(),
which resolves to <body> when nothing is focused) so the event fires and its
default action can run, and add a Tab branch to handleKeydown that performs
HTML sequential focus navigation: move focus to the next (Shift+Tab:
previous) focusable element ordered by tabindex, then document position.
The order is computed from tabindex + tree position, so no layout is needed.

Closes #2699
2026-06-11 13:44:08 +02:00
Karl Seguin
d0dad60a9e bridge: Remove snapshot create fallback
If the comptime snapshot isn't valid, we currently create the snapshot on the
fly (as if -Dsnapshot_path wasn't specified). This change now returns an error.
This eliminates a good chunk of code when -Dsnapshot_path. It replaces a silent
fallback with a hard-fail. The advantage is that it's explicit..if you specify
-Dsnapshot_path you either use the snapshot or it fails.

Note: Snapshot.create came up when analyzing the binary as being particularly
big. But in our release build, it's dead code. I didn't expect it to change
RSS, but I thought it couldn't hurt to try, and in the end, I like this change
anyways.
2026-06-11 18:58:30 +08:00
Karl Seguin
0c1bb406c0 ci: Include v8 version in Snapshot cache key 2026-06-11 17:12:55 +08:00
Adrià Arrufat
19581f34ce agent: simplify model and provider output 2026-06-11 11:04:30 +02:00
Adrià Arrufat
7d554846c1 build: update isocline dependency 2026-06-11 11:01:19 +02:00
Francis Bouvier
7e9acec50f agent: Improve save prompt (#2691) 2026-06-11 10:09:59 +02:00
Francis Bouvier
bdf8bd1031 agent: Improve agent script doc (#2692)
* ci: raise cdp bench MAX_VmHWM to 29000

The agent branch grew .text by ~2.8MB (mostly std monomorphization from
the new script/agent modules); none of it executes in serve mode and
anonymous/heap memory is byte-identical to main (716-724KB Private_Dirty
across main, agent-dev, and a build with the agent code compiled out).

The VmHWM delta is file-backed pages of the binary: the kernel maps them
in large readahead/THP chunks around each touched page, so peak RSS
shifts with link layout on every relink. The agent-less test build
measured 4.2MB *below* main while running the identical serve path,
purely from folio/window boundaries moving. At 28000 the gate was
failing on layout noise (28028-28064), not a regression.

* agent: improve docs agent_script

* Revert "ci: raise cdp bench MAX_VmHWM to 29000"

This reverts commit b6b704d43e.

---------

Co-authored-by: Adrià Arrufat <adria.arrufat@gmail.com>
2026-06-11 09:51:50 +02:00
Adrià Arrufat
b0cf88b6a8 agent: improve extract tool description (#2696)
Co-authored-by: Francis Bouvier <francis@lightpanda.io>
2026-06-11 09:42:47 +02:00
Adrià Arrufat
314e3c58ea Merge branch 'main' into agent
# Conflicts:
#	src/mcp/Server.zig
2026-06-11 09:00:44 +02:00
Karl Seguin
e667e279fb webapi: Implement Element.offsetParent getter
Saw this missing API on in the wild, wasn't breaking there.
2026-06-11 15:00:23 +08:00
Rohit
331aa6a71a refactor(viewport): source hardcoded 1920x1080 from MediaQuery.Viewport.default
The default viewport dimensions were duplicated across six independent
sites. Point window.innerWidth/innerHeight, screen.width/height/availWidth,
visualViewport.width/height, Page.getLayoutMetrics and the
IntersectionObserver root rect at the single MediaQuery.Viewport.default
(which already documents itself as the rewire point).

No behavior change: every site keeps the same 1920x1080 values, now from
one source. This is the groundwork requested on #2664 so a future
Emulation.setDeviceMetricsOverride can move all of them together.
2026-06-11 11:59:51 +05:30
Karl Seguin
a70c3cefb8 perf, http: Preload modules
Similar to https://github.com/lightpanda-io/browser/pull/2675. That PR added
support for rel=preload, this one adds it for rel=modulepreload. The impact here
is generally less significant. Modules were already asynchronously preloaded
as part of the module-loading flow. What this does is potentially start the
preload earlier (i.e. when the link is encountered).  You can imagine:

// pseudo-html
<link rel=modulepreload href=mod1.js>
<link rel=modulepreload href=mod2.j2>

<script src=s1.js></script>
<script src=s2.js></script>

If s1.js imports mod1 and mod2, then there won't be a huge difference...I mean
mod1 and mod2 can start loading before s1.js is complete, but it won't be huge.
If s1.js doesn't import mod1 and/or mod2, but s2.js does, then the gain is a
little more (because now we have to wait for both s1 and s2 to load). So it
really depends.

This commit also better manages preloaded scripts. There were common cases where
a preloaded script might remain preloaded until page teardown..well past its
actual usage. This happened because, while every preload increments the waiters
count, only the first to fetch it decrements it. Once cached, waiters was never
decremented. This is now fixed.
2026-06-11 14:19:31 +08:00
Karl Seguin
d695ce10c3 Merge pull request #2690 from lightpanda-io/log_shrink
log, mem: Reduce generated code size of logger
2026-06-11 13:52:38 +08:00
Karl Seguin
b145519fc3 Merge pull request #2688 from lightpanda-io/script_reentrency_too_strict
script: Force pending script evaluation after evalutate finishes
2026-06-11 12:32:13 +08:00
Karl Seguin
93346ef5a6 mem: reduce generic use in log
Experiment to see if this shrinks the build by any significant amount. Some
investigation did surface this as some of the code we control directly which
did stand out.
2026-06-11 10:21:57 +08:00
Karl Seguin
96becbd296 log, mem: Make scope and msg runtime values to shrink generated code size 2026-06-11 08:41:57 +08:00
Karl Seguin
def62ebfa0 Apply endEvaluationWindow in more places 2026-06-11 07:18:14 +08:00
Karl Seguin
b0426bab9b Merge pull request #2685 from lightpanda-io/shadow-dom
wpt, shadowdom: Improve shadowdom
2026-06-11 06:45:24 +08:00
Karl Seguin
e8e9b0356a script: Force pending script evaluation after evalutate finishes
This commit is in the same vein as 0d9482ccbf. A
dynamic async script which completes during an evalute() does not evaluate if
`is_evaluating == true`. That's good, but we need to make sure that it _does_
eventually get evaluated. As-is, we rely on a done callback to call evaluate()
again which works for all but the last script.

This commit creates a more robust reentrancy flow. is_evaluating still guards
against reentrancy, but a new flag, `evaluate_pending` is set to true. Whenever
`is_evaluating` is set to false if `evaluate_pending` is true, we evaluate().

Similalry, during evaluate(), we better handle completed scripts during
evaluate() and process them immediately (via an outer loop).
2026-06-10 20:14:05 +08:00
Pierre Tachoire
e2fc3918a0 Merge pull request #2683 from lightpanda-io/mcp-ping-object 2026-06-10 13:56:29 +02:00
Karl Seguin
d1f4c40920 Merge pull request #2671 from navidemad/datatransfer-api
webapi: DataTransfer / DataTransferItem / DataTransferItemList + DragEvent (drag-and-drop file upload)
2026-06-10 19:08:07 +08:00
Navid EMAD
fefc1931b9 webapi: address DataTransfer review feedback
- DataTransferItem/DataTransferItemList/Iterator forward acquireRef/releaseRef
  to the owning DataTransfer, so its pooled arena outlives any JS-held wrapper
  (fixes a potential use-after-free when JS keeps an item/list/iterator alive
  past the DataTransfer).
- addItem reads strings straight into the persistent arena via
  toStringSliceWithAlloc, removing the intermediate call_arena copy.
- normalizeFormat uses std.ascii.allocLowerString instead of dupe + lowerString.
- setData: rename dup -> owned_data for clarity.
2026-06-10 12:33:22 +02:00
Adrià Arrufat
a1d427e518 browser: make console capture opt-in (#2686)
Move console message listener registration out of Session initialization
into an explicit `enableConsoleCapture` method. This avoids buffering
console logs when they are not needed.
2026-06-10 11:12:59 +02:00
Karl Seguin
caeb359f75 wpt, shadowdom: Improve shadowdom
This was driven by various WPT tests in the /shadow-dom/ category. There are
4 distinct changes.

1. Template hooks into "cloned" to include the _content. This change required
   passing `deep: bool` which is why TextArea and Input are also changed (they
   ignore that new parameter)

2. Node.getRootNode and Node.ownerDocument will now traverse through the
   ShadowRoot to find the root/document

3. DOM events won't gain the Window when triggered from within a ShadowRoot

4. attachShadow now takes a full option, not just a string mode. This also
   touched a few different places since it's called internally too.
2026-06-10 15:28:11 +08:00
Karl Seguin
6bead7becd Merge pull request #2676 from lightpanda-io/intersection_observer_perf
perf; Optimize IntersectionObserver
2026-06-10 07:43:59 +08:00
Karl Seguin
843de5cd0e Merge pull request #2675 from lightpanda-io/script_preload
perf,http: Support for script preloading
2026-06-10 07:43:42 +08:00
Adrià Arrufat
668c5d1628 Merge branch 'main' into agent 2026-06-09 19:07:31 +02:00
Adrià Arrufat
4b3e18fda2 agent: extract save helpers to save.zig (#2684)
* Revert "agent: enhance /save progress and verification feedback"

This reverts commit 54f467d1fa.

* Revert "agent: verify synthesized scripts during /save"

This reverts commit b141da30ca.

* agent: extract save helpers to save.zig

Moves pure helper functions related to the `/save` command (parsing,
validation, file writing, prompt shaping) from `Agent.zig` to a
dedicated `save.zig` module.
2026-06-09 19:06:09 +02:00
Pierre Tachoire
a52c45f309 mcp: ping's response must be an object not an array
The array returned breaks the mcp keep alive feature implemented by the
official mcp client in Go.
2026-06-09 17:40:08 +02:00
Adrià Arrufat
54f467d1fa agent: enhance /save progress and verification feedback
- Add step-by-step progress reporting during script synthesis.
- Introduce yellow warning bullets for superseded verification runs.
- Refactor bullet emission in Terminal to support multiple statuses.
- Fix spinner formatting when tool arguments are empty.
2026-06-09 17:35:31 +02:00
Adrià Arrufat
b141da30ca agent: verify synthesized scripts during /save
Introduces a multi-step synthesis process for `/save` that derives a
logical JSON output schema and uses a dry-run runtime to verify
candidate scripts. The LLM can now run and self-correct its scripts
using a new `run_script` tool before finalizing the save.
2026-06-09 16:53:39 +02:00
katie-lpd
b23c6c27bc Update agent.md 2026-06-09 16:21:56 +02:00
Adrià Arrufat
1a6ee90da7 Merge pull request #2681 from lightpanda-io/katie-lpd-patch-1
Update agent-tutorial.md
2026-06-09 15:55:07 +02:00
katie-lpd
1186e43f06 Update agent.md
Moving tutorial after quickstart for fluidity
2026-06-09 15:53:30 +02:00
katie-lpd
a48dd45163 Update agent.md 2026-06-09 15:49:34 +02:00