Enable the offscreen web extension API
Component: WebKit WebExtensions | 3708229
Source/WTF/wtf/PlatformEnableCocoa.h
Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
The Offscreen API lets a WebExtension spin up a hidden document context to run DOM-dependent logic (parsing, media, clipboard) without a visible window, mirroring Chrome's Offscreen Documents API. Until now, ENABLE_WK_WEB_EXTENSIONS_OFFSCREEN was defined as 0 && ENABLE_WK_WEB_EXTENSIONS, which compiled the feature out entirely regardless of the runtime preference; the preference itself also defaulted to off.
This commit removes both gates at once, so the offscreen-document code paths are now both compiled in and enabled out of the box wherever WebExtensions are supported. It also replaces a C-style cast with dynamic_objc_cast in the windowScene lookup, a safer-CPP cleanup flagged by the ios-safer-cpp bot:
Before:
ENABLE_WK_WEB_EXTENSIONS_OFFSCREEN = 0 && ENABLE(WK_WEB_EXTENSIONS) → always compiled OUT
WebExtensionOffscreenEnabled default = false → runtime OFF
After:
ENABLE_WK_WEB_EXTENSIONS_OFFSCREEN = ENABLE(WK_WEB_EXTENSIONS) → compiled IN when extensions enabled
WebExtensionOffscreenEnabled default = true → runtime ON by default
Significance
A previously compiled-out extension API surface becomes reachable by default to any installed WebExtension, expanding what untrusted extension code can trigger inside WebKit.
Audit directions
This code path was compiled entirely out of shipping builds until now, so it has had far less fuzzing and real-world exposure than mainstream WebExtension APIs. Narrow: the extension permission logic, offscreen document lifecycle management, and the IPC boundary between the extension context and the offscreen WebPage in WebExtensionContextAPIOffscreenCocoa.mm are all live attack surface — start with how offscreen documents are created and torn down relative to extension teardown, since a document outliving its owning context is the natural first lifetime bug in a feature of this shape. Wider: the reusable hunting pattern is a feature whose compile-time gate and runtime preference flipped in the same commit — grep PlatformEnable*.h for other 0 && short-circuits and cross-reference against UnifiedWebPreferences.yaml entries still marked testable, since each represents code that shipped-build fuzzers have never reached. When one of those flips, its IPC message handlers deserve the same first-exposure audit this one does.