Commit graph

1375 commits

Author SHA1 Message Date
Tim Ledbetter
e16618bdd1 LibWeb: Apply textBaseline offset in Canvas measureText() 2026-01-15 10:31:23 +01:00
Tim Ledbetter
191e8218dc LibWeb: Use correct font metrics calculations in Canvas measureText() 2026-01-15 10:31:23 +01:00
Andreas Kling
cf5e0a31ee LibWeb: Avoid synchronous layout update on window.scroll(0, 0)
The coordinate (0, 0) is always inbounds, and we don't need to consult
layout results to figure out if it's within the scrollable overflow.
2026-01-14 11:46:23 +01:00
Christoffer Haglund
14ccc87190 LibWeb: Address edge case on async module load
Issue #6294 describes an edge case where the browser crash if the same
module is loaded three times in a document, but all attempts fail.

Failure scenario:
1. Module load 1 set the state to "Fetching"
2. Module load 2 registers a callback to `on_complete` since the
   current state is "Fetching"
3. Module load 1 finish with a failure, invoking the callback for load
   number 2
4. Module load 3 cause a crash. The state is neither "Fetching" or
   "ModuleScript", so we'll reset the state to "Fetching". This invokes
   the callback for module load 2 again, now with an unexpected state
   which will cause an assert violation.

Proposed fix is to remove the condition that invokes `on_complete`
immediately for successfully loaded modules only, the callback should
be invoked regardless of whether the fetch succeeded or failed.

This reveals a separate bug in HTMLScriptElement, where
`mark_as_ready()` can be invoked before
`m_steps_to_run_when_the_result_is_ready` is assigned.
This appears to be a spec bug, reported as
https://github.com/whatwg/html/issues/12073 and addressed by delaying
the callback by a task, similar to the issue was resolved for inline
scripts.
2026-01-13 18:12:38 +01:00
Shannon Booth
1106496d1c LibWeb/HTML: Ensure data: URL workers are same-origin with themselves
See: baff3f5
2026-01-13 16:59:54 +01:00
Gingeh
fbde887cc8 LibWeb: Remove API URL character encoding
See https://github.com/whatwg/html/pull/9755/
2026-01-13 13:51:32 +00:00
Shannon Booth
9eabaa6833 LibWeb/HTML: Set correct length for cross-origin wrapper functions 2026-01-13 10:11:31 +01:00
Shannon Booth
399c62933a LibWeb/HTML: Set correct name for cross-origin wrapper functions 2026-01-13 10:11:31 +01:00
Shannon Booth
d49939e230 LibWeb/HTML: Do not capture GC::Roots in cross origin function objects
JS::NativeFunction should be GC safe, so we should not be capturing
GC roots as it may cause memory leaks.
2026-01-13 10:11:31 +01:00
Jelle Raaijmakers
64f1e6e11a LibWeb: Add onanimation* event handler IDL attributes
Add these animation event handlers to GlobalEventHandlers:
- onanimationcancel
- onanimationend
- onanimationiteration
- onanimationstart

They were missing, causing `window.onanimationend = ...` style
assignments to silently fail.
2026-01-13 10:09:22 +01:00
Tim Ledbetter
ba7b0c60f0 LibWeb: Move hyperlink navigation methods to DOM::Element
This allows us to use these methods from `SVGAElement` without
inheriting  `HTMLHyperlinkElementUtils`, which we can't do for
`SVGAElement` due to a naming conflict with the `href()` method in
`SVGURIReferenceMixin`.
2026-01-13 10:05:40 +01:00
Tim Ledbetter
cf3a49cda6 LibWeb: Use href content attribute value in follow_the_hyperlink()
Previously we were using the IDL attribute value, which didn't follow
the specification.
2026-01-13 10:05:40 +01:00
Tim Ledbetter
0448731059 LibWeb: Remove unnecessary methods from HTMLHyperlinkElementUtils
These could all be implemented in terms of
`hyperlink_element_utils_element()`.
2026-01-13 10:05:40 +01:00
Tim Ledbetter
82db5c3f20 LibWeb: Parse Referrer-Policy header when creating policy container
Previously, when creating a policy container from a fetch response, the
Referrer-Policy HTTP header was not being parsed. This meant documents
loaded with a Referrer-Policy header would ignore the policy and use the
default.
2026-01-12 13:07:14 +01:00
Tim Ledbetter
1022ec3b4a LibWeb: Set referrer policy on navigation fetch requests 2026-01-12 12:47:40 +01:00
Jonathan Gamble
e090532c3e LibWeb: Remove a WTF comment that got moved outside of its context
This comment at the end of LibWeb/HTML/Focus.cpp:
```
  // What? It already doesn't have system focus, what possible
  // platform-specific conventions are there?

```
Originally followed and referred to this FIXME on line 319:
```
  // FIXME: Otherwise, apply any relevant platform-specific conventions
  // for removing system focus from topDocument's
  // browsing context, and run the focus update steps with old chain,
  // an empty list, and null respectively.
```
During the course of #7233, it was accidentally moved and attached
to a different context, following this comment below on line 325:
```
  // NOTE: The unfocusing steps do not always result in the focus
  // changing, even when applied to the currently focused
  // area of a top-level traversable. For example, if the currently
  // focused area of a top-level traversable is a
  // viewport, then it will usually keep its focus regardless until
  // another focusable area is explicitly focused
  // with the focusing steps.
```

Rather than move it to the correct place and become its git blame
villain in the process, I once more seek to remove it.
2026-01-12 11:31:08 +00:00
Jonathan Gamble
555681bdb5 LibWeb: Split PaintableWithLines from PaintableBox
No functional changes. I just hope to improve code navigation.
2026-01-12 11:00:14 +00:00
Tim Ledbetter
79a427e1ef LibWeb: Implement HTMLImageElement x() and y() getters
These attributes get the image's top left border edge  relative to the
root element's origin.

These methods ignore any transforms.
2026-01-11 00:33:08 +01:00
Psychpsyo
52781cc2fd LibWeb: Add WebXR's XRSystem 2026-01-11 00:01:24 +01:00
Shannon Booth
14634c970f LibWeb/HTML: Align OffscreenCanvas.convertToBlob to latest spec
See: 903d277
2026-01-10 23:11:43 +01:00
Shannon Booth
5652975f32 LibWeb/HTML: Don't call ToString during Error serialization
This was not a specification issue, a non-string value will just
not match against any of the names and will fall back to Error,
so we should avoid the call of ToString here.
2026-01-10 21:30:04 +01:00
sideshowbarker
1b41659efd LibXML+LibWeb: Use existing HTML entities table for XML parsing too
For XHTML documents, resolve named character entities (e.g.,  )
using the HTML entity table via a getEntity SAX callback. This avoids
parsing a large embedded DTD on every document and matches the approach
used by Blink and WebKit.

This also removes the now-unused DTD infrastructure:

- Remove resolve_external_resource callback from Parser::Options
- Remove resolve_xml_resource() function and its ~60KB embedded DTD
- Remove all call sites passing the unused callback
2026-01-09 19:13:41 +00:00
Jonathan Gamble
f84e6f8acf LibWeb: Make input controls relinquish focus on outside clicks
Model "viewport focus" with Document::focused_area == nullptr.

Focus.cpp:
  When a blur occurs, remove the document entry from the old chain
  before running the focusing steps. This ensures the document atop the
  new chain is not discarded. Focus::run_focus_update_steps will then
  set focused_area to nullptr, indicating viewport focus.

EventHandler.cpp:
  Split hit testing in handle_mousedown. Use an exact hit test for
  focus/blur decisions, and a subsequent cursor hit test for
  selection/caret.
2026-01-09 18:09:09 +01:00
Jelle Raaijmakers
ae20ecf857 AK+Everywhere: Add Vector::contains(predicate) and use it
No functional changes.
2026-01-08 15:27:30 +00:00
Sam Atkins
8a0ba904b9 LibWeb/HTML: Return Promises from Window scroll methods
A version of this was added in a610639119
and reverted in 70671b4c11. The bugs
there (confusing scroll-to-position and scroll-by-delta, and not having
an execution context in some cases) have been fixed in this version.
2026-01-08 14:50:09 +00:00
Sam Atkins
0a57e1e8ac LibWeb: Clarify some scrolling-related code
A lot of our scrolling code is quite old, and doesn't match the spec,
but does use some similar names. This is quite confusing. In particular
`perform_scroll_of_viewport()` is not the same as the spec algorithm.
That algorithm is actually almost implemented in
`scroll_viewport_by_delta()`.

To clarify things, this commit makes a few changes:
- Rename perform_scroll_of_viewport() to
  perform_scroll_of_viewport_scrolling_box(). This is a better match
  for how we use this method, even if it's not actually a match for the
  algorithm. (:yakbait:)
- Move `scroll_viewport_by_delta()`'s code into a new
  `perform_a_scroll_of_the_viewport()` method, and make it take a
  position like it should. `scroll_viewport_by_delta()` now calls it
  with a calculated position.

I've avoided reusing the original `perform_scroll_of_viewport()` name to
avoid accidents.
2026-01-08 14:50:09 +00:00
CountBleck
a4051cca11 LibWeb: Serialize "auto" ByteLengths correctly in StructuredSerialize
When a "length-tracking" TypedArray/DataView is postMessage'd, the
view seen by the recipient should still be "length-tracking". However,
this wasn't the case, because the actual length was serialized, as
opposed to the JS::ByteLength, which includes the "auto" state to
signal the presence of this "length-tracking" behavior.

This fixes two subtests in...
https://wpt.live/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.html
2026-01-08 00:55:52 +01:00
CountBleck
515828d971 LibWeb: Serialize Error#cause in StructuredSerialize
The spec doesn't include this behavior (at least, not yet), but all
browsers do this, as can be seen in several subtests in
https://wpt.live/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.html
2026-01-08 00:55:52 +01:00
Andreas Kling
2ac363dcba LibGC: Only call finalize() on types that override finalize()
This dramatically cuts down on time spent in the GC's finalizer pass,
since most types don't override finalize().
2026-01-07 20:51:17 +01:00
sideshowbarker
fac81e84ba LibXML: Replace the existing XML parser with libxml2 parsing
This change replaces our LibXML parser with a new implementation that
wraps libxml2's SAX2 API.

The new Parser class uses libxml2's SAX2 callbacks to drive the existing
XML::Listener interface. That preserves backward compatibility with all
existing consumers (XMLDocumentBuilder, DOMParser, etc.).
2026-01-07 14:38:52 +01:00
Andreas Kling
a9cc425cde LibJS+LibWeb: Add missing GC marking visits
This adds visit_edges(Cell::Visitor&) methods to various helper structs
that contain GC pointers, and makes sure they are called from owning
GC-heap-allocated objects as needed.

These were found by our Clang plugin after expanding its capabilities.
The added rules will be enforced by CI going forward.
2026-01-07 12:48:58 +01:00
Sam Atkins
77b14f8e5f LibWeb/HTML: Account for fixed-positioning CBs in offsetParent
Corresponds to:
743e65324f
2026-01-06 15:54:57 +00:00
Sam Atkins
fd55d03061 LibWeb/HTML: Account for fixed-positioning CBs in scrollParent 2026-01-06 15:54:57 +00:00
Lorenz A
528695230b LibWeb: Implement set_value_of_indexed_property closer to spec text 2026-01-06 13:03:41 +01:00
Lorenz A
7e50dcb687 LibWeb: Update spec text for set_value_of_indexed_property
https://github.com/whatwg/html/pull/11932 resolved the AD-HOC comment
and adjusted the spec text.
2026-01-06 13:03:41 +01:00
Lorenz A
48f08ba09d LibWeb: Bump dom tree version to invalid cache on select select_options 2026-01-06 13:03:41 +01:00
Lorenz A
3e296a1b92 LibWeb: Mirror options collection on the select element 2026-01-06 13:03:41 +01:00
Tim Ledbetter
584e0996c9 LibWeb: Store color as a StyleValue in FilterOperation::DropShadow 2026-01-06 12:13:13 +01:00
Shannon Booth
8a8383d59d LibWeb/HTML: Invalidate frozen ports array on initMessageEvent
In the case that initMessageEvent is called (even with the same
ports), we should return a new array object. This fixes an issue
where the cached m_ports_array was not cleared, causing the
attribute to return the old object identity.
2026-01-06 11:49:06 +01:00
InvalidUsernameException
831cecd644 LibJS+LibWeb: Add missing visits for cached cross-origin properties
This was causing GC-related crashes on various websites, most
prominently on any site that contains embedded YouTube videos. The issue
can be reproduced by going to any YouTube video, using the _Share_
button below it and pasting the embed code into an empty HTML file and
loading it through localhost.

This is technically a regression from
89dbdd3411 in that the problem became
visible with that commit. However, there is nothing wrong with the
commit by itself. It just happens that `Origin::is_same_origin_domain()`
prior to that commit was completely bogus and would mistakenly return
true in almost all cases, so the cross-origin code paths were not
exercised.

I am uncertain how to make a automatic test case for this problem, given
the nature of it being GC- and cross-origin-related. So there is no
regression test included in this commit.
2026-01-06 00:01:01 +01:00
Luke Wilde
2058c05d50 LibGfx: Create Gfx::Bitmap for PaintingSurface in ImmutableBitmap 2026-01-05 15:56:15 +01:00
Callum Law
79740b04b3 LibWeb: Don't generate layer for background-image none entry
Reduces the time spent in `background_layers()` from 1.5% to 0.04% when
loading https://en.wikipedia.org/wiki/2023_in_American_television
2026-01-05 11:35:26 +00:00
Jonathan Gamble
7385569a02 LibWeb: Selection toString focused text control delegation
Allows selected text in form controls to be copied to clipboard.
2026-01-02 18:40:05 +01:00
R-Goc
15cb3e872e LibWeb: Use static cast to cast from base class
It is not guaranteed that inherited classes have the same address as the
base of the derived class. In that case a reinterpret cast leads to
undefined behavior. This occured on msvc ABI. See:
https://godbolt.org/z/jGeEW3c48

Co-authored-by: ayeteadoe <ayeteadoe@gmail.com>
2026-01-01 12:23:15 +01:00
Shannon Booth
f9a996650b LibWeb/HTML: Implement the Origin interface
See: 68909b2
2025-12-30 12:40:27 +01:00
Jonathan Gamble
f6f4d7f497 LibWeb: Move <input> handle_return_key logic to HTMLInputElement 2025-12-29 19:59:42 +01:00
Jonathan Gamble
e39f73f978 LibWeb: Fix tofu in textarea newlines on MacOS
Do not insert the codepoint from the platform event. Always insert 10
2025-12-29 19:59:42 +01:00
Shannon Booth
2a8b83a568 LibWeb/WebIDL: Upgrade QuotaExceededError to its own interface
See 48eba6d
2025-12-29 17:15:11 +01:00
Tete17
fdb01e7f93 LibWeb: Add the Crypto task source
This is used by the spec to queue tasks to resolve or reject promises
created in response to calls to methods of SubtleCrypto.
2025-12-28 18:56:50 +01:00
Aliaksandr Kalenik
9a2931527a LibWeb: Use ConservativeVector in get_session_history_entries()
This way we ensure doc states traversal queue elements are visited.
2025-12-27 18:40:21 +01:00