Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 4ce58a7ff78ce27cf6646691c6ddfb966b22b51c
      
https://github.com/WebKit/WebKit/commit/4ce58a7ff78ce27cf6646691c6ddfb966b22b51c
  Author: Brian Weinstein <[email protected]>
  Date:   2026-08-31 (Mon, 31 Aug 2026)

  Changed paths:
    M Source/WebCore/workers/service/server/SWServer.cpp
    M Source/WebCore/workers/service/server/SWServer.h
    M Source/WebCore/workers/service/server/SWServerJobQueue.cpp
    M Source/WebCore/workers/service/server/SWServerRegistration.cpp
    M Source/WebCore/workers/service/server/SWServerRegistration.h
    M Source/WebKit/UIProcess/API/Cocoa/WKWebExtensionContext.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebExtensionContextPrivate.h
    M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm
    M Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIOffscreen.mm

  Log Message:
  -----------
  Extension service worker loses clients when it is unloaded and reloaded
https://bugs.webkit.org/show_bug.cgi?id=322881
rdar://186116488

Reviewed by Timothy Hatcher.

When an extension service worker is reloaded, it loses track of the client 
registrations. Make
sure that the service worker has the correct knowledge of its registrations 
when it
has been unloaded and reloaded.

Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIOffscreen.mm

* Source/WebCore/workers/service/server/SWServer.cpp:
(WebCore::SWServer::didReconnectServiceWorkerPage): Remove the previous 
identifier from the map,
add the new one.
(WebCore::SWServer::unregisterServiceWorkerClientInternal): Add a branch if the 
registration has any clients.
If so, clear the service worker page identifier and terminate the workers, 
instead of clearing the registration
entirely.
* Source/WebCore/workers/service/server/SWServer.h:
* Source/WebCore/workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::runRegisterJob): Restore existing service worker 
connections.
* Source/WebCore/workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::clear): Call 
terminateWorkersForServiceWorkerPageDisconnect (pulled into a helper method).
(WebCore::SWServerRegistration::terminateWorkersForServiceWorkerPageDisconnect):
 Move some code that used to be in
SWServerRegistration::clear into its own method.
* Source/WebCore/workers/service/server/SWServerRegistration.h:
(WebCore::SWServerRegistration::setServiceWorkerPageIdentifier):
* Source/WebKit/UIProcess/API/Cocoa/WKWebExtensionContext.mm:
(-[WKWebExtensionContext _reloadBackgroundContentForTesting]): Call into the 
WebExtensionContext C++ object.
* Source/WebKit/UIProcess/API/Cocoa/WKWebExtensionContextPrivate.h:
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::reloadBackgroundContentForTesting): Unload and 
load the background web view.
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIOffscreen.mm:
(TestWebKitAPI::TEST_F(WKWebExtensionAPIOffscreen, 
OffscreenDocumentVisibleToClientsMatchAllAfterBackgroundContentReloads)): This
test creates an offscreen web view, and makes sure that it is still a client 
after the service worker is unloaded and reloaded.

Canonical link: https://commits.webkit.org/320198@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to