Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 7682d9817bed6645aa2516eb20a1b5a2ca48d735
https://github.com/WebKit/WebKit/commit/7682d9817bed6645aa2516eb20a1b5a2ca48d735
Author: Timothy Hatcher <[email protected]>
Date: 2026-06-27 (Sat, 27 Jun 2026)
Changed paths:
M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm
M Source/WebKit/UIProcess/Extensions/WebExtensionContext.cpp
M Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIRuntime.mm
Log Message:
-----------
runtime.sendMessage from a content script is dropped if sent while the
background content is still loading.
https://webkit.org/b/317981
rdar://177298426
Reviewed by Kiara Rose.
When a content script called runtime.sendMessage before a non-persistent
background page or service worker had finished its initial load and registered
its runtime.onMessage listener, the message was delivered to no listener and
silently dropped instead of being queued until the background content loaded.
This happened reliably on the first load after install, or whenever the
persisted background listener state had been cleared, because the empty
listener set made wakeUpBackgroundContentIfNecessaryToFireEvents() treat the
event as unhandled rather than deferring it.
Until the background content has loaded once, an empty listener set means the
listeners aren't known yet, not that the event is unhandled, so queue the task
to fire after the background content loads rather than dropping it. Track this
with m_backgroundContentHasLoadedOnce so that once the background has loaded an
empty set remains authoritative and unhandled events still avoid waking it.
Forwarding events during the initial load also exposed a latent bug where
didOpenWindow() did not forward its SuppressEvents argument to didOpenTab(),
causing pre-existing tabs enumerated by populateWindowsAndTabs() to fire
tabs.onCreated; that spurious event was previously masked by the early-out.
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::unload): Reset m_backgroundContentHasLoadedOnce
so the
cleared listener set is treated as unknown again on the next load.
(WebKit::WebExtensionContext::didOpenWindow): Forward suppressEvents to
didOpenTab() so
tabs of windows enumerated during the initial population don't fire
tabs.onCreated.
(WebKit::WebExtensionContext::performTasksAfterBackgroundContentLoads): Set
m_backgroundContentHasLoadedOnce once the background content has finished
loading.
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.cpp:
(WebKit::WebExtensionContext::wakeUpBackgroundContentIfNecessaryToFireEvents):
Queue the
event instead of dropping it when the listener set is empty and the background
has never
loaded, since the handling listener may register during the in-flight load.
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h: Add
m_backgroundContentHasLoadedOnce.
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIRuntime.mm:
(TestWebKitAPI::TEST): Add
SendMessageFromContentScriptWhileBackgroundIsLoading, which
sends a content-script message while the background content races its initial
load.
Canonical link: https://commits.webkit.org/315975@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications