Commit Graph

1023 Commits

Author SHA1 Message Date
Sam
9f1e5d084e script: Pass &mut JSContext in FetchResponseListener::process_response_eof (#42729)
`process_response_eof` is the only method that needs cx at least right
now. This PR removes one temp_cx and introduces one, removing that one
will is hard (needs VirtualMethods and a lot of work)

Testing: Just refactor
Part of #40600

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-02-20 16:03:21 +00:00
shuppy
c07682f222 libservo: Allow the embedder to activate accessibility (#42336)
this patch adds a Servo::set_accessibility_active() method that
embedders can use to tell Servo to start building and sending
accessibility trees to the platform, as long as the pref is enabled
(#42333). doing so sets a global flag in the constellation, which is
then propagated to the layout of all existing and future pipelines.

Testing: none yet, no functional change
Fixes: part of #4344

---------

Signed-off-by: delan azabani <dazabani@igalia.com>
Signed-off-by: Alice Boxhall <alice@igalia.com>
Co-authored-by: Alice Boxhall <alice@igalia.com>
2026-02-20 05:56:15 +00:00
atbrakhi
3c8c46d32f devtools: implement pause and resume in debugger (#42580)
When a breakpoint is hit, the script thread now pauses execution and
notifies devtools clients with a "paused" event. The script
thread enters a loop that processes devtools messages until
a Resume command is received.

This change does not implement manual pause

Testing: Added new test
Fixes: part of https://github.com/servo/servo/issues/36027




https://github.com/user-attachments/assets/c619db20-4579-4f77-aa60-0e43e6e7e575

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
2026-02-18 10:08:46 +00:00
Martin Robinson
6842da5f5b script: Use the Weak<ScriptThread> reference for tracing instead of thread-local storage (#42657)
This changes makes it so that tracing accesses the `ScriptThread` via a
weak reference set on the `Runtime` rather than thread local storage.
The idea is to use TLS less and less as time goes on. This is done by
creating a new data structure that holds all the data that is necessary
for SpiderMonkey callbacks in the `ScriptThread`.

Testing: This should not change behavior in a way that is observable
via testing.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-02-16 14:45:55 +00:00
Gae24
c13d8a2eff script: Start using &mut JSContext in devtools and webdriver code (#42640)
This is a first step to compile scripts using `&mut JSContext`.

Testing: Refactor, covered by existing WPT tests.
Part of #40600

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2026-02-16 08:32:08 +00:00
Josh Matthews
ab85eafc7e Revert "script: Introduce end of loading phases" (#42562)
Reverts servo/servo#42446 . Too many new intermittent timeouts caused by
missing document load events.

Fixes: #42555
Fixes: #42556
Fixes: #42560
Fixes: #42557
Fixes: #42561 
Fixes: #42559 
Fixes: #42554
2026-02-12 04:10:30 +00:00
Tim van der Lippe
94f418c6e6 script: Introduce end of loading phases (#42446)
Since the steps for
https://html.spec.whatwg.org/multipage/parsing.html#the-end are
scattered throughout various pieces, it has been difficult to figure out
when to run what.

To remedy that, introduce the concept of phases. These phases are
checked in every method that needs to
"Spin the event loop" to know whether

1. It is the appropriate time to continue with #the-end
2. It has fully achieved its goal

For example, when processing deferred scripts, we need to do this after
a deferred script has finished loading. But we also need to do it at the
start of parsing, since we might not have any deferred scripts at all.

Therefore, each previous step sets the appropriate phase and calls the
corresponding next step. Each step then verifies its conditions and
continues if required.

Part of #41972

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
2026-02-11 21:45:14 +00:00
Simon Wülker
929e275fcd devtools: Show attached event listeners in inspector tab (#42355)
This change makes the devtools inspector show any event listeners that
are attached to a node. The primary motivation is making the devtools
more useful for debugging real-world websites.

<img width="536" height="268" alt="image"
src="https://github.com/user-attachments/assets/5ba13e41-14b4-4202-b994-eadff5d1c6b5"
/>

You can also click on the event listener to show some more info, though
most of that (everything except the event type and the event phase) is
currently just placeholder text:

<img width="1360" height="456" alt="image"
src="https://github.com/user-attachments/assets/ec025847-43fc-489c-8b26-46afb6dada64"
/>


Testing: This change adds a new test

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2026-02-11 13:31:25 +00:00
atbrakhi
d6097d1967 devtools: Implement debugger Eval event (#42306)
Replace the `EvaluateJS` function to use `debugger.js` `Eval` event and
the proper context. This takes the global context and calls
[executeInGlobal](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Object.html#executeinglobal-code-options).

In future we also add the version that takes a frame and calls
[eval](https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Frame.html#eval-code-options).

Testing: No new tests added yet, Old tests are not impacted by this
change.
Fixes: Part of https://github.com/servo/servo/issues/36027

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: eri <eri@igalia.com>
2026-02-09 12:58:51 +00:00
Mukilan Thiyagarajan
79ed814ec1 libservo: Expand the UserContentManager API. (#42288)
The patch adds the following functionality to the per-WebView
`UserContentManager` API.
- Removing a `UserScript` at that was previously added.
- Adding a new `UserStyleSheet` representing a user-origin style sheet.
allow removing user script
- Removing a previously added `UserStyleSheet`.

There might be scope for some improvements in the API:
- `UserScript` and `UserStyleSheet` have different ways of representing
the source location - a `PathBuf` and `Url` respectively. This is due to
how those values are used by the underlying evaluation APIs in script
and stylo. More investigation is needed here and could be addressed in
future patches.

Testing: New unit tests are added for the user stylesheet APIs. Existing
tests have been updated to test the removal of user scripts.
2026-02-05 13:26:54 +00:00
Osoro Bironga
8d4f2db3c9 script: Start a performance timeline entry for iframe documents (#42270)
Added resource timing that was missing for an iframe document.

Testing: Added
Fixes: https://github.com/servo/servo/issues/41666

---------

Signed-off-by: Osoro Bironga <fanosoro@gmail.com>
2026-02-03 16:07:10 +00:00
Narfinger
db052c4990 script: Change some HashSets to FxHashSet (#42257)
This changes 3 occurences of HashSet to FxHashSet for speed
improvements:
- dom/notifications::pending_request_ids: Pending Request ids are
Uuid::new_v4, hence, not user assignable.
- script_thread: painters_generating_frames: These are pipeline ids and,
hence, ideal for FxHash.
- script_thread:: docs_with_no_blocking_loads: These are Dom<Document>
and their hash is the ptr address, so ideal for FxHash.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: These do not change functionality.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2026-01-30 17:02:58 +00:00
Steven Novaryo
45c39d7496 script: Notify PinchZoom resizes to ScriptThread's VisualViewport (#41754)
Continuing the implementation of `VisualViewport`, the resizing of
`PinchZoom` should be notified to `ScriptThread` to update the
`VisualViewport` interface and to fire the appropriate JS event. Top
level `Window`/`Pipeline` would have a `VisualViewport` interface that
mirrors the `PinchZoom` viewport, while nested `Window` would have a
default value that represent layout viewport of the relevant iframe. The
`VisualViewport` of an iframe is updated after each reflow that
calculate the rectangle of the iframe.

The updates of DOM's `VisualViewport` occurs immediately (instead of
waiting for the event loop like the viewport) but integrates with the
event loop for the JS events. This behavior would helps with the fact
that `VisualViewport` needs to be updated both when it is scrolled or
resized.

Testing: Existing WPTs and new unit test.
Part of: https://github.com/servo/servo/issues/41341

---------

Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
2026-01-28 09:33:55 +00:00
Tim van der Lippe
c0b55a2c34 script: Add about_base_url (#42104)
We populate the required field for all relevant entrypoints
and set it to `document.base_url` when the url is `about:blank`
or `about:srcdoc`. In all other cases, it uses
`document.about_base_url`.

Testing: WPT
Fixes #41836

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-01-27 18:09:01 +00:00
atbrakhi
e28a0f6d6c devtools: implement clearBreakpoint (#42154)
Add an event listener for `clearBreakpoint` to `debugger.js` and the
necessary glue to access it from the `devtools` crate.

Testing: `./mach test-devtools` and manual testing.
Fixes: Part of: https://github.com/servo/servo/issues/36027

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: eri <eri@igalia.com>
2026-01-27 15:46:54 +00:00
Martin Robinson
9c9d9c863f Rename compositing and compositing_traits to paint and paint_api (#42066)
This change finishes the big rename associated with the old
`compositing` crates. Long ago, these crates managed a compositor, like
you might find in a traditional web engine. These days, compositing is
done in WebRender so the name has stopped making much sense. Various
structs inside the crates have already been renamed and this is the
final big change necessary for the rename

Testing: This is just a rename so existing tests should cover it.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-01-24 09:17:35 +00:00
Narfinger
71cc3b2382 WebGPU: Use GenericChannel (#42032)
Switching WebGPU component to use GenericChannel.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: Compilation is the test.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2026-01-21 05:59:18 +00:00
eri
151074e9a1 devtools: Handle pause in the debugger (#42007)
Add an event listener for `pause` to `debugger.js` and the necessary
glue to access it from the `devtools` crate. This returns important
information to know where we are paused, such as the source location and
frame state.

Fix frame and object actor encoding into messages. Use information from
`debugger.js` to correctly fill the fields.

Add a new `frames` list to the thread actor and handle the `frames`
message.

Fix `getEnvironment` reply in the frame actor. It is out of form (has a
`type` field but it doesn't require a followup empty message, it already
counts as a reply), so we need to handle it specially.

Note: For now we are focusing on the protocol side of the debugger, and
this patch only shows where the pause would happen. Pausing Servo itself
will happen in a followup.

![Debugger showing the line where execution would be
paused](https://github.com/user-attachments/assets/c007f205-0ccd-47f1-ad0b-81b7415e8211)

Testing: `mach test-devtools` and manual testing. No errors (apart from
#42006).
Part of: #36027

---------

Signed-off-by: eri <eri@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2026-01-19 19:27:52 +00:00
Josh Matthews
a97a345d6e script: Check same-origin-domain when evaluating javscript: URLs. (#41969)
These changes introduce a new OriginSnapshot type, which is an immutable
version of MutableOrigin (ie. an origin that includes an optional domain
modifier). This is now propagated as part of LoadData's origin, allowing
us to perform the same-origin-domain check for javascript: URLs as
needed.

Testing: Newly-passing tests.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2026-01-18 02:32:51 +00:00
shuppy
c2530a49ee Plumb accessibility tree updates from layout to embedder (#41924)
this patch adds some new methods and messages that allow layout to send
the embedder [accessibility tree
updates](https://docs.rs/accesskit/0.22.0/accesskit/struct.TreeUpdate.html):

- layout —[ ScriptThreadMessage::AccessibilityTreeUpdate ]→ script
- script —[ EmbedderMsg::AccessibilityTreeUpdate ]→ libservo
- libservo —[ WebViewDelegate::notify_accessibility_tree_update() ]→
servoshell
- servoshell —[ PlatformWindow::notify_accessibility_tree_update() ]→
servoshell
- servoshell —[ Gui::notify_accessibility_tree_update() ]→ servoshell

Testing: none yet, no functional change
Fixes: part of #4344

---------

Signed-off-by: delan azabani <dazabani@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Alice Boxhall <alice@igalia.com>
2026-01-16 12:32:08 +00:00
eri
9d35414386 devtools: Handle the setBreakpoint message. (#41925)
Listen for `setBreakpoint` on `debugger.js` and add the relevant WebIDLs
and Servo counterparts to trigger this event and notify SpiderMonkey.

Implement `find_source` for `SourceManager` and `find_offset` for
`SourceActor`.

Testing: Manual testing and `./mach test-devtools` (note, the latter
seems to have some failing tests, we are investigating this, but this
patch doesn't add any new failure).
Fixes: Part of #36027

---------

Signed-off-by: eri <eri@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
2026-01-16 10:17:55 +00:00
Laurent Belmonte
0dc28296e0 script: Some failed requests should record resource timing entries (#41804)
Some failed requests should record resource timing entries

Testing: ./mach test-wpt
tests/wpt/tests/resource-timing/entries-for-network-errors.sub.https.html
Fixes: https://github.com/servo/servo/issues/41667

---------

Signed-off-by: bellau <laurent.belmonte@gmail.com>
2026-01-14 13:20:12 +00:00
Euclid Ye
014fb968a8 webdriver: Consolidates synchronous and asynchrounous script execution (#41830)
Follow-up to #41823.
Now that we always execute JS with callback, we can safely remove the
obsolete sync script handler.

- Rename `ExecuteAsyncScript` to `ExecuteScriptWithCallback`
- Remove `ExecuteScript` related logic.
- Rewrite async callback wrapper to simplify things.

Testing: I expect no change in behaviour. See if WPT tests agree with
it.

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2026-01-11 09:19:09 +00:00
WaterWhisperer
2a759ed6de Replace allow(crown::unrooted_must_root) with expect(crown::unrooted_must_root) (#41815)
Testing: `./mach build -d --use-crown` with no warnings
Fixes: #41761

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2026-01-10 08:05:49 +00:00
Sam
5173ea12cd script: More &mut JSContext in codegen (#41808)
Reviewable per commit. First commit adds `&mut JSContext` to
`call_default_constructor`. Second commit adds `&mut JSContext` to
Interface, which in unfortunately required many changes (a lot of
passing `&mut JSContext` down).

Testing: Just a refactor, but should be covered by WPT
Part of #40600

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-01-09 14:50:54 +00:00
Sam
89067e5450 script: Pass &mut JSContext to tasks (#41756)
This change is reviewable per commits:
In first commit we added `&mut JSContext` to `run_box` (it is very hard
to bring `&mut JSContext` to `remove_script_and_layout_blocker`).
In second commit we pass `&mut JSContext` to `run_once`.
In third commit we added support for accepting `&mut JSContext` in
closures of `task!` macro and lastly we demo new macro invocations (to
ensure they actually compile)

Testing: Just refactor, but should be covered by WPT
Part of #40600

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-01-08 07:49:27 +00:00
Sam
38306eaf7b script: Init and pass down &mut JSContext in script-related threads (#41692)
1. removed `ScriptThread::get_safe_cx` in favor of `Runtime::cx` (this
intentionally shadows
[RustRuntime::cx](https://doc.servo.org/mozjs/rust/struct.Runtime.html#method.cx),
which is not really safe with all other stuff that happen in servo).
2. passed down cx from `ScriptThread::new` to accommodate those changes
(we also need to pass cx for some other stuff).
3. we create JSContext in workers/worklets, so we can pass all the way
down to
6ccc47f4c9/components/script/dom/workers/workerglobalscope.rs (L1013)
(so we can get &mut JSContext in tasks).

So with this PR, we prepared all entry points of JSContext (or other
should actually be reentering via SM callback or passed down from the
root one in the thread).

Testing: No changes just safety, but it should be covered by WPT
Part of #40600

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-01-06 18:27:10 +00:00
Tim van der Lippe
d44c38998c net: Keep track of size of keep-alive records (#41457)
These keep-alive records live on the `CoreResourceManager` since the vec
of records must be modified by the fetch thread. The script thread
sometimes
requires this information as well, which is why it can send a message to
obtain the total size.

The keep-alive records must be tracked per global. That's why all code
needs
to specify the `pipeline_id`. Requests optionally have this field, which
is why
the code expects it to be present. The relevant information is added to
the
navigator request to ensure it can compute it.

Fixes #41230

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-01-05 18:22:58 +00:00
Narfinger
94eafd4ef9 script: Store a Weak handle to ScriptThread in both ScriptThread and Window (#40645)
We construct `ScriptThread` in an `Rc` which itself has the given `Weak`
for it. It then can give it to `Window` and other elements in the
future. We currently only use this for the microtask checkpoint function
in `Window`. This is the first step toward eliminating the usage of
thread local storage to access the `ScriptThread`.

Testing: This should not change behavior so is covered by existing
tests.
Fixes: Part of addressing:
https://github.com/servo/servo/issues/37969#issuecomment-3520463442

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2026-01-05 13:20:19 +00:00
Sam
d1ba789482 script: Obtain &mut JSContext at the start of the script and pass it down to msg handlers (#41564)
At the start of the script we create first (and only[^1]) safe
`JSContext`, from where we should pass it down to every code that needs
the cx. This PR brings it all the way down to message handlers. There is
clear separation between functions that use new model `&mut JSContext`
and the ones that use the old model (usually they take can_gc).

[^1]: Another place of construction are SM hooks (that pass us down raw
JSContext), but to reach that point we already needed to call another
function that takes `&mut JSContext`, so one can look at this case as
reentering/reborrowing (we derive new shorter `&mut JSContext` from the
old one).

Testing: This is just refactor, but should covered by WPT tests.
Part of #40600

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-12-30 18:19:41 +00:00
Sam
ffa4864f49 script: Remove redundant realm entering (#41565)
`spawn_pipeline` does not need realm entered and
`handle_fullscreen_exit` does realm entering on it's own:
133c9b4266/components/script/script_thread.rs (L2503)

try run: https://github.com/sagudev/servo/actions/runs/20567048851

Signed-off-by: Sam <16504129+sagudev@users.noreply.github.com>
2025-12-29 12:11:09 +00:00
Mukilan Thiyagarajan
2ccd9f54ad libservo: Let UserContentManager be per WebView and add basic support for mutations. (#41352)
This change moves the `UserContentManager` abstraction from the
`ServoBuilder` to `WebViewBuilder` so that embedders can inject content
for each `WebView` independently. It also adds basic support for runtime
mutations to the `UserContentManager` API. Only adding new scripts is
currently supported, but future changes will add support for both other
mutations such as removal of scripts and addition & removal of
stylesheets. Future changes could also optimize the way mutations are
propagated to `ScriptThread`s by sending just the "delta" rather than
the whole `UserContents` structure for each mutation.

The `UserContentManager` now becomes just a convenient handle for the
embedders to invoke the mutation API while the actual management of the
manager's content is handled by the Constellation. The mutations are
relayed to the constellation via messages. The change also separates the
serialized version containg the user contents into a new `UserContent`
structure so that the API cannot be misused.

Testing: New unit tests have been added for the different scenarios
involving UserContentManager.

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2025-12-23 06:15:01 +00:00
Jan Varga
1a6b18937a libservo: Add initial SiteDataManager::site_data API (#41378)
This PR adds an initial `site_data` API to `SiteDataManager`, allowing
embedders to obtain a unified list of sites that have associated site
data.

The implementation introduces supporting infrastructure across storage
and
`SiteDataManager` layers, including a small helper for obtaining
WebStorage
origins and initial support for filtering by storage type. At this
stage,
sites correspond directly to origins, future work will extend this to
higher
level grouping (e.g. domain or eTLD+1).

Testing: Added a new integration test covering site data behavior across
localStorage and sessionStorage.

---------

Signed-off-by: Jan Varga <jvarga@igalia.com>
2025-12-21 12:45:43 +00:00
Simon Wülker
b0734b7f2d script: Make same-origin iframes inherit encoding from their container document (#41450)
Testing: new tests start to pass
Part of https://github.com/servo/servo/issues/6414

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-12-21 11:03:30 +00:00
Simon Wülker
8c344f5641 script: Prescan byte stream to determine encoding before parsing document (#41376)
Servo currently completely ignores `<meta charset>` tags. When we find
one with an encoding that is incompatible to the current one, then we
should reload the page and start over with the new encoding. A common
optimization that has even made its way into the specification is to
wait for a few bytes to arrive and inspect them for `meta` tags, so the
browser is able to use the correct encoding from the very beginng.

In practice, I've run into problems with our WPT harness when reloading
the page after `meta` tags. Therefore, this change implement the
optimization first, so we never have to reload when running WPT. I've
implemented prescanning in a way where we wait for 1024 bytes to arrive
or for one second to pass, whichever one happens first.

This causes a large number of web platform tests to flip around. I've
looked at most of the new failures and I believe they're reasonable.

Testing: New tests start to pass.
Part of https://github.com/servo/servo/issues/6414

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-12-19 09:54:19 +00:00
Tim van der Lippe
3ac02bc6ac script: Mark fetch-later requests as keep-alive (#41345)
This implements the required plumbing for the keep-alive flag on
requests. The flag already exists on the request object, but now also
exists on the builder itself.

The flag is then passed into a canceller. While we could make canceller
optional, in many cases it isn't and would require a whole lot more
changes. To follow the spec more closely, opted to put the keep_alive
flag on the canceller as well.

Note that this doesn't pass any extra fetch-later tests since we are not
correctly unloading iframe documents. That will be fixed in a follow-up
PR.

Part of #41230

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-12-18 19:49:13 +00:00
Martin Robinson
824f551f03 Rename IOCompositor to Paint (#41176)
For a long time, the "Compositor" hasn't done any compositing. This is
handled by WebRender. In addition the "Compositor" does many other
tasks. This change renames `IOCompositor` to `Paint`.

`Paint` is Servo's paint subsystem and contains multiple `Painter`s.
This change does not rename the crate; that will be done in a
followup change.

Testing: This just renames types and updates comments, so no new tests
are necessary.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-12-10 15:09:49 +00:00
Martin Robinson
87eeae7047 script: Remove reference to closed bug #18998 (#41162)
This bug was closed a while ago, so we should also remove in in code
reference to it.

Testing: This just removes an out-of-date comment so no tests necessary.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-12-09 17:46:06 +00:00
Narfinger
6f62269c8c Devtools: Switch to GenericChannel and GenericCallback (#41051)
Switch the devtools part to GenericCallback and GenericSender.
To keep the diff small the names where not changes as a Sender almost
fills the same requirement as a callback.

Testing: As this is mostly type changes, the compilation is the test but
also devtools seem to work fine with these changes. ./mach try run is
here: https://github.com/Narfinger/servo/actions/runs/19931697694

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-12-08 11:03:45 +00:00
Gae24
ae62ab7fa7 script: Expose a single interface to run js code on globalscope (#41078)
Small cleanup, avoid repeating some code, since in these cases we use
the defaults provided by `GlobalScope`

Testing: Covered by existing tests, no behaviour change.

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
2025-12-05 15:27:52 +00:00
webbeef
27a776b060 script: shorten script thread name (#41033)
On Linux thread names are limited to 15 characters: that caused all the
script threads to be named 'ScriptScriptEve' and show up with the same
name in tooling.

That changes turns the name to 'Script#{script id}' instead.

Testing: No test coverage for that very internal detail.

Signed-off-by: webbeef <me@webbeef.org>
2025-12-03 19:43:04 +00:00
dyegoaurelio
194875ee35 Block and report CSP violations for javascript: URLs in window.open (#40997)
Previously, when window.open() was called with a javascript: URL, the
script would execute unconditionally without any CSP enforcement. The
CSP list was not propagated from the opener to the newly opened
document.

This commit fixes two issues:

1. Propagate CSP from opener to new document The CSP list from the
existing (opener) document is now copied to the target document before
navigation, ensuring CSP policies are enforced.

2. Report CSP violations to the correct window Per the CSP spec,
violations should be reported to the navigation request's client (the
opener window), not the target window. To achieve this, we check CSP
early in window.open() while both windows are accessible, before
entering the normal navigation flow where only the target window is
available.


Testing: new wpt successes:
-
`content-security-policy/script-src/javascript-window-open-blocked.html`
-
`content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-window_open.html`
-
`content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-window_open.html`


Fixes: part of #36437

Signed-off-by: Dyego Aurélio <dyegoaurelio@gmail.com>
2025-12-02 06:23:36 +00:00
Martin Robinson
2503684d84 constellation: Break the EventLoop dependency on the initial Pipeline (#40944)
Currently starting a script `EventLoop` depends on sending data about
the initial `Pipeline`. This change breaks this dependency. The goal
here is to:

1. Allow `ScriptThread`s to be shared between `WebView`s. This will
   allow more flexiblity with the way that `ScriptThread`s are created,
   which should allow us to perserve system resources by allowing them
   to be shared between `WebView`s. With this change, we can do away
   with the `InitialPipelineState` entirely, which was gather
   information necessary for both a new `EventLoop` and a new
   `Pipeline`. We no longer have to do many clones when reusing an
   existing even loop.
1. Simplify the way that `EventLoop`s and `Pipeline`s are spawned. Now
   `Pipeline`s are spawned in the same way no matter what.

Now the general order of operations when starting a pipeline is:

1. Get or create an event loop for the pipeline:
    - If the event loop needs to be spawn, spawned it in a new thread or
      process.
2. Send the spawn pipeline message to the event loop (kept alive via an
   `Rc`.

Testing: This should not change behavior in a way that is observable, so
should
be covered by existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-29 23:30:17 +00:00
Martin Robinson
08aad55ef7 script: Break the ScriptThread dependency on the initial Pipeline (#40918)
`ScriptThread`s start with an initial `Pipeline`, but that `Pipeline`
should not be used for any `ScriptThread` global data as a
`ScriptThread` can have any number of `Pipeline`s that come and go.
There's no architectural reason why a `ScriptThread` should be
associated with only a single `WebView`.

This change makes it so that the `ScriptThread` no longer uses the
`PipelineId` and the `WebViewId` of the initial `Pipeline` to initialize
itself. Instead a `ScriptEventLoopId` is used to uniquely identify every
`ScriptThread` in both the `ScriptThread` and the `Constellation`.
The remaining use was for crash reporting. Now when a crash happens, it
launches the sad tab in all `WebView`s that depeneded on that
`ScriptThread`.

This is a change which should allow simplifying the way that
`EventLoop`s/`ScriptThread`s are started in the `Constellation`, which
will be handled in a followup.

Testing: This shouldn't change behavior except in the case where a
`ScriptThread` is used in more than a single `WebView`, which should
work
properly now. I tested this change manually by running servoshell in
multiprocess mode while causing a panic to happen due to a null pointer
dereference. The sad tab appeared after this change, so things seem to
work
properly still. Testing crashes is tricky with the way we test servo
now.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-27 13:34:57 +00:00
Mukilan Thiyagarajan
90595e3570 compositing: Support per-Painter operations and message handling (#40788)
Currently, only the first `Painter` is used for all operations in the
`Compositor`. This change modifies the compositor API and message
handling to allow routing the operations to the correct `Painter` via a
provided `PainterId` or `WebViewId`.

This change is to enable support for per-`WebView`s `RenderingContext`s.

Testing: This change shouldn't change behavior, so existing WPT tests
should cover it.

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-11-21 13:15:55 +00:00
eri
c6f4c79814 devtools: Support reloading tab (#40760)
Allows to use the reload button from the top bar of `about:debugging`.

<img width="971" height="43" alt="Top bar of about:debugging showing the
tab, title, buttons for back, forward and reload and url bar"
src="https://github.com/user-attachments/assets/5496fcf1-5ee3-41cc-8fdb-53aad020ea96"
/>

Testing: Manual testing.

Signed-off-by: eri <eri@igalia.com>
2025-11-20 12:19:20 +00:00
Tim van der Lippe
e1b9c02de3 webdriver: implement protocol handler automation mode (#40733)
The tests now start running rather than erroring, but they aren't
working yet as we don't currently use protocol handlers yet. That's for
follow-up PRs, as that requires more plumbing.

Part of #40615

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-11-19 11:53:17 +00:00
Martin Robinson
0a1061d8d7 script: Use ScriptEventLoopSender for Runtime event loop callbacks (#40590)
Instead of using a task source for SpiderMonkey runtime callbacks, use a
`ScriptEventLoopSender`. Task sources are associated with a particular
Pipeline, but the runtime callback is run indepenently of any particular
Pipeline and could theoretically happen when no Pipeline exists at all.
This reduces the dependency of the `ScriptThread` on the existence of
the first Pipeline.

Testing: This should not change observable behavior, so is covered by
existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-12 18:16:59 +00:00
Martin Robinson
ab0f818583 script: Consolidate more logic into ScriptThread::spawn_pipeline (#40586)
Have more of the code follow the same path calling
`ScriptThread::spawn_pipeline`. Somewhat tricky was that the `origin` of
the new Pipeline was being determined in several different places, but
all in a consistent way for different types of page loads. This change
makes it is so that the origin is always determined in the same place.

This change is preparation for splitting out the creation of a new
`ScriptThread` and the spawning of its first pipeline.

Testing: This should not change observable behavior, so is covered by
existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-12 15:37:25 +00:00
Martin Robinson
65deada7ef script: Return only a JoinHandle from ScriptThread constructor (#40571)
The `JoinHandle` was added as a newer return value from this
constructor. Both return values accomplish more or less the same thing.
The difference is that the `Sender` return value is triggered right
before the thread ends while the `JoinHandle` is triggered after thread
completion. One was used in multiprocess mode and one in single process
mode. In any case, the `JoinHandle` works fine for both cases.

Testing: Multiprocess isn't tested currently, but I confirmed that the
ScripThread shut down properly in multiprocess mode with this change.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-12 05:40:28 +00:00