LibWeb: Close WebSockets when document is unloaded

Previously, they would stay open for the entire WebContent lifetime,
or until the server closed the connection. This was particularly
noticeable on collaborative websites/games such as
https://jigsawpuzzles.io/, where the user using Ladybird would stick
around even after they had navigated away.
This commit is contained in:
Luke Wilde
2025-02-25 12:41:52 +00:00
committed by Andreas Kling
parent 3224f8acb5
commit 12a07b4fad
5 changed files with 66 additions and 3 deletions

View File

@@ -3905,8 +3905,11 @@ void Document::run_unloading_cleanup_steps()
// 1. Let window be document's relevant global object.
auto& window = as<HTML::WindowOrWorkerGlobalScopeMixin>(HTML::relevant_global_object(*this));
// FIXME: 2. For each WebSocket object webSocket whose relevant global object is window, make disappear webSocket.
// If this affected any WebSocket objects, then set document's salvageable state to false.
// 2. For each WebSocket object webSocket whose relevant global object is window, make disappear webSocket.
// If this affected any WebSocket objects, then set document's salvageable state to false.
auto affected_any_web_sockets = window.make_disappear_all_web_sockets();
if (affected_any_web_sockets == HTML::WindowOrWorkerGlobalScopeMixin::AffectedAnyWebSockets::Yes)
m_salvageable = false;
// FIXME: 3. For each WebTransport object transport whose relevant global object is window, run the context cleanup steps given transport.