Commit Graph

8347 Commits

Author SHA1 Message Date
Adrià Arrufat
8abbd6d9c0 Script: handle duplicate argument keys and URL query params 2026-05-25 19:25:58 +02:00
Muki Kiboigo
f4de603cf5 properly deinit transfer on runNextTick 2026-05-25 10:09:53 -07:00
Muki Kiboigo
a828a5cd78 properly wait for all next ticks to be flushed 2026-05-25 10:06:50 -07:00
Muki Kiboigo
766e163ef1 properly handle cancellation of next tick events 2026-05-25 10:06:50 -07:00
Muki Kiboigo
a295a7a21a various changes to properly track next ticked transfers 2026-05-25 10:06:50 -07:00
Muki Kiboigo
cd5e5ece40 serve from cache on next client tick 2026-05-25 10:06:49 -07:00
Muki Kiboigo
274ee25fb2 add NextTickQueue to HttpClient 2026-05-25 10:06:17 -07:00
Adrià Arrufat
9b4a48e07f Merge branch 'main' into agent 2026-05-25 18:18:55 +02:00
Adrià Arrufat
6e7a4420e3 terminal: deduplicate error and warning printing
Extracts the common printing logic from `printError` and `printWarning`
into a new `printSeverity` helper function.
2026-05-25 18:18:20 +02:00
Adrià Arrufat
fbec560292 Ref: #123
fix: address various stability and reliability issues

- Cache stderr TTY check in Config to optimize log hot path.
- Cap signal handler attempts during no-hard-exit.
- Always duplicate URL segments to prevent invalid frees.
- Write live file before backup in atomic writes.
- Settle microtasks before verifying DOM elements.
2026-05-25 18:05:11 +02:00
Adrià Arrufat
4bc5baf7ee agent: improve command diagnostics and fix various bugs
- Add diagnostics to command parsing to report invalid field values.
- Fix UTF-8 truncation in spinner to avoid splitting codepoints.
- Fix swapped arguments in log error formatting.
- Distinguish "null" values from missing elements in verifier.
- Handle MCP tool cancellation and timeouts with specific error codes.
2026-05-25 17:51:46 +02:00
Adrià Arrufat
4ad59b07b3 console: use warn severity for console.warn 2026-05-25 17:40:06 +02:00
Adrià Arrufat
7532cd1df4 session: cap console message size to remaining budget 2026-05-25 17:39:49 +02:00
Adrià Arrufat
8ca2975b1d browser: catch implicit form submit error on Enter
Prevents form submission failures from blocking the subsequent keyup
event, which could cause UIs waiting on keyup to hang.
2026-05-25 17:37:15 +02:00
Adrià Arrufat
e519d84318 tools: default checked to true in execSetChecked 2026-05-25 17:36:06 +02:00
Adrià Arrufat
df5fbf4bc3 command: require locator for null args in isRecorded
Tool calls like click or hover with null arguments are unreplayable
and should not be considered recorded, even if they have zero
required fields.
2026-05-25 17:33:08 +02:00
Karl Seguin
d2b495113c Improve document.write within an iframe
This fixes two things. First, it better tracks the calling context and the
target context, so that if a parent frame does a document.write within a child
frame, any JavaScript is executed in the child frame's context (previously, it
would be executed in the parent's context).

Second, it ensures that, on document.write, we force-execute any pending
scripts. This is related to https://github.com/lightpanda-io/browser/pull/2542
but applies specifically to document.write.
2026-05-25 20:46:53 +08:00
Karl Seguin
0d9482ccbf Immediately run deferred inline scripts after "load" is fired
Currently, any inline deferred script, e.g:

<script type=module>
...
</script>

That happens AFTER load, never executes. Unclear how serious an issue this is,
but it _does_ cause problems for some WPT tests which use document.write to
inject a <script type="module">...</script> block after an iframe is loaded.
2026-05-25 18:16:44 +08:00
Karl Seguin
d03215492c implement import.meta.resolve 2026-05-25 16:54:52 +08:00
Karl Seguin
24639890a7 make websocket work in worker 2026-05-25 13:29:37 +08:00
Karl Seguin
8472d21c59 Accessibility: use content for name for specific role
For typically name-less elements, check the "role" attribute to see if we should
fallback to the content.

Improves a handful of WPT tests, e.g.: /accname/name/comp_text_node.html

(It seems impossible to get 100% on these tests without knowing what is and
isn't a block-level element which would require more knowledge in the
StyleManager).
2026-05-25 12:46:20 +08:00
Karl Seguin
9dc81f129c Merge pull request #2538 from lightpanda-io/feat-implement-file-api
Feat implement file api
2026-05-25 12:10:41 +08:00
Karl Seguin
d3c5c31a93 deduplicate File and Blob init 2026-05-25 11:36:17 +08:00
Karl Seguin
dc4218159a Merge pull request #2523 from navidemad/fix/2363-about-blank-replaces-document
Replace active page on synthetic root navigation (about:blank, blob:)
2026-05-25 09:19:30 +08:00
Karl Seguin
43a592d2fc small dedupe for arena release 2026-05-25 09:05:37 +08:00
Adrià Arrufat
adc76d2cc1 agent: fix tool output capping and tokenizer escape handling
- Limit UTF-8 walkback in `capToolOutput` to 3 bytes to prevent
  excessive scanning on malformed input.
- Track consecutive backslashes in `tokenize` to correctly handle
  even-count backslashes before a closing quote.
2026-05-24 12:18:05 +02:00
Adrià Arrufat
634566f4b8 agent: truncate tool output at UTF-8 boundary 2026-05-24 11:48:22 +02:00
Adrià Arrufat
aed5bbf1b6 schema: reject backslash escapes in quoted values
Explicitly reject backslash-escaped quotes with a clear error
message, suggesting alternative quote styles or triple quotes.
Bare backslashes (e.g. in Windows paths) remain supported.
2026-05-24 11:35:07 +02:00
Adrià Arrufat
4a58a9043e tools: reject invalid backendNodeId in tree tool 2026-05-24 11:25:41 +02:00
Adrià Arrufat
d469fdc88c tools: normalize PascalCase argument keys from LLMs 2026-05-24 11:22:42 +02:00
Adrià Arrufat
bd861f5ac0 mcp: rename tools to camelCase 2026-05-24 11:13:56 +02:00
Karl Seguin
43102317aa Merge pull request #2524 from willmafh/auth_challenge_parse_bugfix
bugfix: get scheme correctly when there is any leading whitespace
2026-05-24 16:44:00 +08:00
Adrià Arrufat
1151e03181 mcp: index multi-line blocks as single spans
Detects multi-line block openers (e.g., `/eval '''`) and indexes the
entire block up to its closing fence as a single span. This prevents
body lines from being indexed individually and orphaned during splicing.
Falls back to single-line indexing if the block is unterminated.
2026-05-24 10:31:08 +02:00
Armaan Sandhu
a7e3bea672 feat(webapi): implement W3C File API 2026-05-24 13:04:33 +05:30
Adrià Arrufat
3381f64ad9 mcp: handle CRLF line endings in indexLines
Strip carriage returns from CRLF line endings before indexing so that
LLM-supplied keys (using plain LF) match files saved with Windows
line endings. The span still covers the full CRLF sequence.
2026-05-24 09:00:31 +02:00
Adrià Arrufat
09698045c6 tools: refuse getCookies without active page
Return an error message instead of dumping all cookies when no page
is loaded and no filter is provided.
2026-05-24 09:00:19 +02:00
Adrià Arrufat
0c58184137 Cookie: make host matching case-insensitive 2026-05-24 08:46:55 +02:00
Adrià Arrufat
525c3e467c input: centralize password value redaction
Introduces `Input.getRedactedValue` to mask password values in
LLM-facing dumps (semantic tree, forms, AXNode) instead of
exposing raw values or using ad-hoc checks.
2026-05-24 08:36:23 +02:00
Adrià Arrufat
ddd9c84195 agent: update zenai and tune agent settings 2026-05-23 23:36:07 +02:00
Adrià Arrufat
8721bfb69e Spinner: prevent line wrapping and multi-line breaks
Strips control characters from tool arguments to avoid breaking the
carriage-return redraw. Queries the terminal width and truncates
arguments to fit on a single row, appending an ellipsis if needed.
2026-05-23 17:22:47 +02:00
Adrià Arrufat
6a0801a6f6 agent: add user turn before slash tool call
Gemini requires that a function call follow a user or function-response
turn. Record the user input before the synthetic assistant tool call.
2026-05-23 14:46:32 +02:00
Adrià Arrufat
4c06fe482f agent: record slash commands as tool calls
Mirrors user-typed slash commands into the message history as synthetic
tool calls. This ensures the LLM conversation remains in sync and the
next prompt can see the action's result.
2026-05-23 11:54:48 +02:00
Adrià Arrufat
0670823905 script: rename mcp_driver_guidance to driver_guidance
Rename the system prompt constant to reflect its broader usage.
Also add instructions to guide the agent on handling follow-up
questions after navigation.
2026-05-23 11:24:36 +02:00
Adrià Arrufat
424f315f27 browser: fix premature timeouts and handle eval navigation
- In Runner, sleep and poll on idle tick instead of failing early.
- In tools, await queued navigations after eval and report the new page.
2026-05-23 10:52:24 +02:00
willmafh
2d48926f1e bugfix: get scheme correctly when there is any leading whitespace 2026-05-23 12:39:34 +08:00
Karl Seguin
67a9aba79c Log on lack of Reaction scope in debug
Flag Range.cloneContents as CEReactions

setAttributeNode triggers single reaction, rather than a remove + add.
2026-05-23 07:52:35 +08:00
Karl Seguin
a8f01ae253 Skip reaction scope for getters 2026-05-23 07:52:34 +08:00
Karl Seguin
ca20a2c7f6 Use backup queue when one doesn't exist
Turns a crash into a slightly delayed (incorrect) execution order which has some
basis in the spec.
2026-05-23 07:52:34 +08:00
Karl Seguin
89814fd855 Fix ce_reactions audit gaps and iterator-invalidation UAF
popAndInvoke captured the reactions queue as a slice at loop entry. If
firing a reaction triggered a nested scope whose enqueue grew the
underlying ArrayList, the captured slice became dangling and the next
iteration read freed memory. Switch to indexed iteration so the queue
pointer is re-read each step. Repros via wpt/custom-elements/
enqueue-custom-element-callback-reactions-inside-another-callback.html.

The rest of the diff adds .ce_reactions = true to bridge declarations
that were missing it per WebIDL [CEReactions] *and* whose Zig impl
actually performs a DOM/attribute mutation (verified by reading each
setter). Without the flag, the algorithm's enqueue path hits
assertScopeActive and panics. Runtime-state-only setters (Input.value,
Input.checked, Select.value, Option.selected, Media.muted/volume, etc.)
are deliberately left untagged.

Covered:
- CustomElementRegistry.define, .upgrade
- HTMLDocument: body, title, dir
- Document: open, close
- HTMLElement base: insertAdjacentHTML, dir, hidden, lang, tabIndex,
  title, innerText
- Range: insertNode, deleteContents, extractContents,
  surroundContents, createContextualFragment
- Selection: deleteFromDocument
- HTMLOptionsCollection: add, remove
- DOMStringMap (dataset): namedIndexed setter/deleter — required adding
  .ce_reactions to NamedIndexed.Opts in bridge.zig
- ~28 HTMLxxxElement files: every settable attribute that resolves to
  setAttributeSafe/removeAttribute (Anchor, Button, Canvas, Data,
  Details, Dialog, FieldSet, Form, IFrame, Image, Input, Label, Link,
  LI, Media, Meta, OL, OptGroup, Option, Quote, Script, Select, Slot,
  Style, TableCell, Template, TextArea, Time, Track, Video)
2026-05-23 07:52:34 +08:00
Karl Seguin
6eeb97c220 CustomElement Reactions
While this PR touches a lot of files, and isn't trivial, many of the changes
are either:
1 - removing guards added in previous PRs, e.g.
    https://github.com/lightpanda-io/browser/pull/1969
    https://github.com/lightpanda-io/browser/pull/2172
    https://github.com/lightpanda-io/browser/pull/2313
    https://github.com/lightpanda-io/browser/pull/2366

2 - Adding the `.ce_reactions = true` flag to various WebAPIs

CustomElements have callbacks, e.g. connectedCallback. Also, many WebAPI calls
are implemented as a series of mutations, e.g. appendChild = remove from current
+ append to new.

These two things interact in an important way: when should callbacks execute?
Before this PR, we were invoking callbacks at each individual step. This is
(a) technically wrong and (b) breaks a lot of assumptions (the reason the above
4 PRs were needed to fix bugs).

This PR adds a `_ce_reactions` queue to the frame. And, instead of invoking
callbacks, we "enqueue" the reaction. At various boundaries, a scope is created
the DOM manipulation is done, and then we pop the scope, invoking all queued
reactions.
2026-05-23 07:52:32 +08:00