Commit Graph

1796 Commits

Author SHA1 Message Date
Zaggy1024
9494f4e8c5 LibWeb: Relayout video elements when setting the initial size
A while ago, we removed the relayout upon rendering a new frame. In
doing so, it became possible for the layout to remain stale after the
video metadata had loaded, leaving the video drawn in a 0x0 box.
2026-04-21 19:11:24 -05:00
Zaggy1024
29d9667511 LibWeb: Always close remote media resource streams on a request error
Otherwise, the PlaybackManager may get stuck waiting for enough data to
read the metadata and call on_metadata_parsed.

This is unfortunately difficult to test without direct control over the
fetching process, but it could cause flakes in tests that wait for
loadeddata.
2026-04-21 19:11:24 -05:00
Tim Ledbetter
e5d615cb11 LibWeb: Implement autofocus candidate processing
This change implements the algorithms necessary to focus elements with
the autofocus attribute on page load.
2026-04-21 23:47:05 +02:00
Jonathan Gamble
baefb51902 LibWeb: Add Media Capture and Stream APIs 2026-04-21 16:40:46 -05:00
Jelle Raaijmakers
6171cb7bbf LibWeb: Override HTMLFormElement::is_supported_property_name()
By implementing this method ourselves, we no longer go through
::supported_property_names() and skip both the vector allocation and
sorting, which we don't need to determine if a property name is present.
2026-04-21 14:02:54 +01:00
Jelle Raaijmakers
e63af74dda LibWeb: Use tree order in HTMLFormElement::supported_property_names()
Calling into ::compare_document_position() for each node comparison
inside quick_sort() is quite expensive - it calculates more than we need
and allocates. Replace it with TreeNode::is_before() which does not, and
gives us the required positional info.
2026-04-21 14:02:54 +01:00
Jelle Raaijmakers
bf414f5d8f LibWeb: Simplify result in HTMLFormElement::supported_property_names()
We were doing the exact same thing as HashTable::values(). No functional
changes.
2026-04-21 14:02:54 +01:00
Shannon Booth
fd44da6829 LibWeb/Bindings: Emit one bindings header and cpp per IDL
Previously, the LibWeb bindings generator would output multiple per
interface files like Prototype/Constructor/Namespace/GlobalMixin
depending on the contents of that IDL file.

This complicates the build system as it means that it does not know
what files will be generated without knowledge of the contents of that
IDL file.

Instead, for each IDL file only generate a single Bindings/<IDLFile>.h
and Bindings/<IDLFile>.cpp.
2026-04-21 07:36:13 +02:00
Shannon Booth
706011bd9b LibWeb: Respect image response MIME type over .svg URL suffix
SharedResourceRequest was treating any URL ending in .svg as SVG, even
when the response Content-Type was some other format (like image/webp).
This could result in transformed CDN image URLs to fail decoding.

Only use the .svg URL suffix fallback when no MIME type was provided.
2026-04-19 15:57:47 +02:00
Jonathan Gamble
1c5907d87f LibWeb: Correct initiator origin logic for new top level traversables 2026-04-19 13:11:48 +02:00
Pavel Shliak
94b29821a1 LibWeb/HTML: Remove duplicate area tag in XMLSerializer 2026-04-19 10:38:32 +02:00
Andreas Kling
354a20217c LibWeb: Handle null active document in destroy_the_child_navigable
When an ancestor document is unloaded, its child documents are unloaded
(and destroyed) first, which leaves their navigable's active document
null. If the ancestor's pagehide handler then removes a subtree
containing one of those iframe containers, destroy_the_child_navigable
crashed dereferencing the null active document.

Treat the "destroy a document and its descendants" step as a no-op when
there is no document left to destroy, and still run the remaining
post-destruction cleanup.

This fixes a crash when closing a GMail tab.
2026-04-16 12:38:38 +02:00
Andreas Kling
e330d5b9ab LibWeb: Make Node::is_connected() O(1) via a cached flag
Previously this walked up the parent chain on every call, which shows
up as a 2.5% item in the profile while watching YouTube videos.

Cache an m_is_connected bit on Node instead, maintained by the DOM
insertion and removal steps.
2026-04-16 08:26:34 +02:00
Andreas Kling
8a9d5ee1a1 LibJS: Separate raw and capturing native functions
NativeFunction previously stored an AK::Function for every builtin,
even when the callable was just a plain C++ entry point. That mixed
together two different representations, made simple builtins carry
capture storage they did not need, and forced the GC to treat every
native function as if it might contain captured JS values.

Introduce RawNativeFunction for plain NativeFunctionPointer callees
and keep AK::Function-backed callables on a CapturingNativeFunction
subclass. Update the straightforward native registrations in LibJS
and LibWeb to use the raw representation, while leaving exported
Wasm functions on the capturing path because they still capture
state.

Wrap UniversalGlobalScope's byte-length strategy lambda in
Function<...> explicitly so it keeps selecting the capturing
NativeFunction::create overload.
2026-04-15 15:57:48 +02:00
Shannon Booth
8642801889 LibWeb: Set fragment scripting mode from the context document
This corresponds with the editorial change to the HTML standard
introducing the parsing mode enum of:

https://github.com/whatwg/html/commit/01c45cede

And a follow up normative change of:

https://github.com/whatwg/html/commit/508706c80

Making fragment parsing derive its scripting mode from the context
document.
2026-04-14 23:01:36 +02:00
Shannon Booth
290db9d690 LibWeb: Set iframe sandbox flags before child navigable creation
The initial about:blank document inherits sandbox flags when the
child navigable is created. Parse the iframe sandbox attribute first
so the initial child document gets the correct sandbox state.

Fixed in the HTML spec with:

https://github.com/whatwg/html/commit/3fd7f35
2026-04-14 23:01:36 +02:00
Shannon Booth
04211d5a51 LibWeb: Propogate sandbox flags when creating a new browsing context 2026-04-14 23:01:36 +02:00
Shannon Booth
de14978046 LibWeb: Implement cross process BroadcastChannel delivery
Route BroadcastChannel messages over IPC so matching channels can
receive them across WebContent and WebWorker processes, rather than only
within a single process.

Each channel now serializes its payload, sends it upward over IPC, and
receiving processes deliver it locally after matching by storage key and
channel name.
2026-04-14 18:43:28 +02:00
Andreas Kling
88d4d1b1a6 LibWeb: Use VM helpers for execution context access
Inline JS-to-JS frames no longer live in the raw execution context
vector, so LibWeb callers that need to inspect or pop contexts now go
through VM helpers instead of peeking into that storage directly.

This keeps the execution context bookkeeping encapsulated while
preserving existing microtask and realm-entry checks.
2026-04-13 18:29:43 +02:00
Andreas Kling
2ca7dfa649 LibJS: Move bytecode interpreter state to VM
The bytecode interpreter only needed the running execution context,
but still threaded a separate Interpreter object through both the C++
and asm entry points. Move that state and the bytecode execution
helpers onto VM instead, and teach the asm generator and slow paths to
use VM directly.
2026-04-13 18:29:43 +02:00
Andreas Kling
ff5273084d LibWeb: Serialize external content surface clears
Lock the shared Skia backend context before clearing an external
content back store.

Nested navigables render through PublishToExternalContent, and that
clear ran outside the locking used by normal display list playback.
This allowed multiple renderer threads to enter the same Ganesh
context concurrently and trip Skia's SingleOwner checks during
painting.
2026-04-13 12:26:14 +02:00
Shannon Booth
482e5e770f LibWeb: Let flexbox stretch auto-width text inputs
Don't rewrite text input 'width: auto' to 'size()ch' in
'HTMLInputElement::adjust_computed_style()'. That turns the control into
a definite-width flex item and prevents 'align-items: stretch' from
expanding it across the flex container.

Fixes the layout of the input element on the element matrix login page.
2026-04-13 09:57:01 +02:00
Shannon Booth
9db0ebe145 LibWeb: Order connectedMoveCallback before adoptedCallback
Corresponds to https://github.com/whatwg/html/commit/f831ea031b42
2026-04-12 18:13:09 +02:00
Tim Ledbetter
6534a58b3c LibWeb: Maintain precision for large valueAsNumber time inputs 2026-04-11 18:28:56 +02:00
Tim Ledbetter
e2e401d0e0 LibJS+LibWeb: Avoid out of range time values in <input> value strings 2026-04-11 18:28:56 +02:00
Sam Atkins
e1e73d485a LibWeb: Left-align the video progress bar
Prevents ancestors of the `<video>` element from moving the bar around.
For example, `<center><video></center>` would cause the progress bar to
start in the center and expand outwards.
2026-04-11 09:38:29 -05:00
Zaggy1024
b7c8537336 LibWeb: Invert the order of sink toggling when selecting video tracks
This ensures that when we're switching from one video track to another,
we don't end up exiting buffering/seeking early due to no tracks being
enabled.
2026-04-10 15:21:07 -05:00
Zaggy1024
bece3c360d LibWeb: Update the ready state after enabling tracks
Otherwise, the buffered ranges used won't include the tracks that are
supposed to be enabled.
2026-04-10 15:21:07 -05:00
Zaggy1024
ac70eb601f LibWeb: Throttle media elements' time marches on ready state updates 2026-04-10 15:21:07 -05:00
Zaggy1024
c11dc9fae9 LibWeb: Prevent reentrancy in HTMLMediaElement::set_ready_state()
We could apparently update the ready state within time_marches_on()
called by set_ready_state(), which could result in triggering autoplay
twice for the same state transition.
2026-04-10 15:21:07 -05:00
Zaggy1024
cb852a7e19 LibWeb: Don't fast seek when seeking media to its current position
This ensures that we don't seek away from the end of the file if we're
already there and fastSeek() is called with a timestamp at or past the
end.
2026-04-10 04:08:28 -05:00
Tim Ledbetter
a8144a2608 LibWeb: Use null-document task when checking is unloading is canceled
Previously, `CheckUnloadingCanceledState::start_phase2()` used
`queue_global_task()` to fire `beforeunload` on each relevant document.
However, tasks associated with a document are only runnable when the
document is fully active and it is possible for the document to become
not fully-active before the task is run. This caused a 15 second delay
in `CheckUnloadingCanceledState` while we waited for a timeout, which
could cause test timeouts when under heavy load.
2026-04-10 00:02:53 +02:00
Shannon Booth
02911253dd LibWeb+LibIPC: Preserve MessagePort queue state across transfer
A MessagePort can be transferred while it already has local queued
state such as incoming messages drained from its transport,
outgoing messages posted before a transport exists, and a pending
shutdown to apply once the port is enabled.

Serialize and restore that state as part of transfer so it moves with
the port instead of being left behind on the old transport.

Also mark transports that are being transferred so shutdown of the old
endpoint during handoff is not reported as peer EOF. That shutdown is
part of moving the transport to the new owner, not peer disconnected.

Co-Authored-By: Alexander Kalenik <kalenik.aliaksandr@gmail.com>
2026-04-09 19:59:16 +02:00
Timothy Flynn
2f3199adbf LibURL+LibWeb: Add a helper to check if a URL is a WebUI URL
Let's not have to know off-hand that we need to update Environments.cpp
when adding a new WebUI. It's more obvious just below where we define
the URLs.
2026-04-09 10:08:06 -04:00
Shannon Booth
57130908b3 LibJS+LibWeb: Make DOMException hold an [[ErrorData]] slot
Split JS::ErrorData out of JS::Error so that it can be used both
by JS::Error and WebIDL::DOMException. This adds support for
Error.isError to DOMException, also letting us report DOMException
stack information to the console.
2026-04-08 20:33:53 +02:00
Callum Law
8bd1b383ea LibWeb: Use correct inherited font size when canvas is not connected
The default font size for a canvas context is 10px as opposed to 16px
for the document as a whole.
2026-04-08 14:31:43 +01:00
Callum Law
c0b23c2124 LibWeb: Ensure canvas style is updated before absolutizing canvas font 2026-04-08 14:31:43 +01:00
Callum Law
f72cab1492 LibWeb: Respect font-variant when setting canvas font 2026-04-08 14:31:43 +01:00
Callum Law
20fb7e64bf LibWeb: Store computed canvas context font value
Previously we stored and exposed the declared value instead
2026-04-08 14:31:43 +01:00
Callum Law
7d15916754 LibWeb: Use correct LRC for absolutizing canvas font values
Canvases belonging to `OffscreenCanvas` and disconnected
`HTMLCanvasElement`s use a LRC based on the initial canvas context font
size of 10px.

This will be covered by WPT tests in a later commit once we expose the
absolutized value in the font getter
2026-04-08 14:31:43 +01:00
Callum Law
4fcb82143b LibWeb: Disallow tree counting functions in most canvas context setters
This matches the behavior of Chrome - tree counting functions are
allowed within on-screen (i.e. not OffscreenCanvas) font values, but
nowhere else.
2026-04-08 14:31:43 +01:00
Callum Law
1fdcea2b7b LibWeb: Disallow random() in canvas context value setters
This introduces two new top-level `ValueParsingContext`s,
`OnScreenCanvasContextFontValue` and `CanvasContextGenericValue`, while
these are handled the same for now, there is a distinction is whether or
not they allow tree counting functions (which will come in a later
commit)
2026-04-08 14:31:43 +01:00
Callum Law
3342fc897f LibWeb: Serialize CanvasTextDrawingStyles::font correctly
Previously we simply serialized a concatenation of the longhand
properties, now we use the correct `font` serialization logic
implemented within `ShorthandStyleValue::serialize`
2026-04-08 14:31:43 +01:00
Callum Law
d4978136e8 LibWeb: Remove old comment in CanvasTextDrawingStyles::set_font
The code this referred to was removed in 32da7ed
2026-04-08 14:31:43 +01:00
Callum Law
27a00f19c5 LibWeb: Update correct value for canvas stroke style setter
When setting to a non-string value (i.e. a `CanvasGradient` or
`CanvasPattern`) we would accidentally update the fill style instead of
the stroke style.
2026-04-08 14:31:43 +01:00
Zaggy1024
84e0b7d36f LibWeb: Increment the fetch generation when cancelling media fetch
The case of an unsupported format error wasn't covered for this,
meaning that it could crash if the fetch completed successfully after
the fetch was cancelled due to such an error.

A crash test is included for this issue, using an echo of a large
corrupted WebM file to ensure that the fetch completes after media
init.
2026-04-08 13:03:39 +02:00
Zaggy1024
6a46bcaf35 LibWeb: Remove an unused capture in the media data request callback 2026-04-08 13:03:39 +02:00
Zaggy1024
a19c40aac5 LibWeb: Move closing of incremental media streams to the fetch cancel
This should ensure that the close() happens in all cases where the
fetch completion may not occur otherwise.
2026-04-08 13:03:39 +02:00
Tim Ledbetter
648ececa62 LibWeb: Remove unused ran_media_element_task variable
Writing to this variable triggered a stack use after return ASAN error.
This variable is safe to remove since it was written to but never read.
2026-04-08 05:10:40 +02:00
Zaggy1024
55262fb6a3 LibWeb: Close IDB connections when the page is destroyed
This fixes a timeout in WPT's abort-in-initial-upgradeneeded.any.html
test. The timeout was a rare one, caused by idbfactory_open.any.html
leaving the second connection in the final test open, since support.js
only tracks the connection created by the first createdb call. By
leaving the connection open, the harness's deleteDatabase() call would
never take effect. This in turn meant that the upgradeneeded test would
fail an assertion on the number of databases. That assertion was also
uncaught by the harness, turning it into a timeout instead of a fail.

By closing the connections when a document is destroyed, we can ensure
that the connection doesn't leak over to the next test and cause the
exception to be thrown.
2026-04-08 03:03:38 +02:00