Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: ccec5e43c6991c10e7e5ba4b8924235930e27255
https://github.com/WebKit/WebKit/commit/ccec5e43c6991c10e7e5ba4b8924235930e27255
Author: Serge Deh <[email protected]>
Date: 2026-04-03 (Fri, 03 Apr 2026)
Changed paths:
M Source/WebCore/automation/AutomationInstrumentation.cpp
M Source/WebCore/automation/AutomationInstrumentation.h
M Source/WebCore/bindings/js/WindowProxy.cpp
M Source/WebCore/bindings/js/WindowProxy.h
M Source/WebDriver/Session.cpp
M Source/WebKit/Scripts/webkit/messages.py
M Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp
M Source/WebKit/Shared/IdentifierTypes.h
M Source/WebKit/Shared/WTFArgumentCoders.serialization.in
M Source/WebKit/UIProcess/Automation/Automation.json
M Source/WebKit/UIProcess/Automation/BidiEventNames.h
M Source/WebKit/UIProcess/Automation/BidiScriptAgent.cpp
M Source/WebKit/UIProcess/Automation/BidiScriptAgent.h
M Source/WebKit/UIProcess/Automation/BidiSessionAgent.cpp
M Source/WebKit/UIProcess/Automation/BidiSessionAgent.h
M Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp
M Source/WebKit/UIProcess/Automation/WebAutomationSession.h
M Source/WebKit/UIProcess/Automation/WebAutomationSession.messages.in
M Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.cpp
M Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.h
M Source/WebKit/UIProcess/Automation/protocol/BidiScript.json
M Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp
M Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h
M Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.messages.in
M WebDriverTests/TestExpectations.json
Log Message:
-----------
[WebDriver BiDi] Implement script.realmCreated and script.realmDestroyed
events
https://bugs.webkit.org/show_bug.cgi?id=304062
rdar://166875337
Reviewed by BJ Burg.
This patch implements the script.realmCreated and script.realmDestroyed events
as specified in the W3C WebDriver BiDi specification. These events notify BiDi
clients when JavaScript execution realms are created and destroyed in browsing
contexts, enabling proper tracking of realm lifecycle for script execution.
* Source/WebCore/automation/AutomationInstrumentation.cpp:
(WebCore::AutomationInstrumentation::scriptRealmCreated): Added with world
filtering.
(WebCore::AutomationInstrumentation::scriptRealmDestroyed): Added with world
filtering.
* Source/WebCore/automation/AutomationInstrumentation.h:
Added scriptRealmCreated and scriptRealmDestroyed methods with DOMWrapperWorld
parameter.
* Source/WebCore/bindings/js/WindowProxy.cpp:
(WebCore::resolveOriginForRealm): Added helper to resolve realm origin.
(WebCore::WindowProxy::destroyJSWindowProxy): Notify realm destruction, with
optional frameForNotification parameter.
(WebCore::WindowProxy::createJSWindowProxy): Notify realm creation.
(WebCore::WindowProxy::setDOMWindow): Notify realm destruction and re-creation
during navigation.
(WebCore::WindowProxy::detachFromFrame): Save frame reference before nullifying
for realm destruction notifications.
* Source/WebCore/bindings/js/WindowProxy.h:
Updated destroyJSWindowProxy signature to accept optional Frame pointer for
notifications during detachment.
* Source/WebDriver/Session.cpp:
(WebDriver::extractEventBrowsingContextIDs): Helper to extract context IDs from
event parameters.
(WebDriver::haveSameElements): Helper to compare vectors for subscription
matching.
(WebDriver::subscriptionMatchesScope): Check if subscription matches event
scope.
(WebDriver::shouldReplayRealmCreatedEvents): Check if realm replay is needed.
(WebDriver::removeSubscribedEvents): Helper to decrement event subscription
counts.
(WebDriver::Session::dispatchBidiMessage): Add context-based event filtering
and realm event replay.
(WebDriver::Session::processLogEntryAdded): Extract event parameters for
context filtering.
* Source/WebDriver/Session.h:
Changed emitActiveBidiScriptRealmCreatedEvents to return void.
* Source/WebDriver/WebDriverService.cpp:
(WebDriver::WebDriverService::emitActiveBidiScriptRealmCreatedEvents): Emit
realm events for active realms.
Handle subscribe command with realm event replay support.
* Source/WebKit/Scripts/webkit/messages.py:
Added WebKit::RealmIdentifier to serialized_identifiers() list for proper IPC
message generation.
* Source/WebKit/Shared/IdentifierTypes.h:
Added RealmIdentifier as ObjectIdentifier<RealmIdentifierType>.
* Source/WebKit/Shared/WTFArgumentCoders.serialization.in:
Added RealmIdentifierType template for ObjectIdentifier serialization.
* Source/WebKit/UIProcess/Automation/Automation.json:
Added emitActiveBidiScriptRealmCreatedEvents command.
* Source/WebKit/UIProcess/Automation/BidiScriptAgent.cpp:
(WebKit::BidiScriptAgent::notifyRealmCreated): Track realm and emit
script.realmCreated event.
(WebKit::BidiScriptAgent::notifyRealmDestroyed): Remove realm and emit
script.realmDestroyed event.
(WebKit::BidiScriptAgent::realmIdentifierForBrowsingContext): Lookup helper for
UIProcess-initiated destruction.
(WebKit::BidiScriptAgent::generateRealmIdForBrowsingContext): Generate realm ID
string from identifier.
(WebKit::BidiScriptAgent::emitEventsForActiveRealms): Emit realm events for all
active realms.
* Source/WebKit/UIProcess/Automation/BidiScriptAgent.h:
Added RealmInfo struct for tracking realm metadata.
Added RealmIdentifier-based realm tracking (m_browsingContextToRealmId,
m_activeRealms).
Added notifyRealmCreated, notifyRealmDestroyed,
realmIdentifierForBrowsingContext, and emitEventsForActiveRealms methods.
* Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::createBrowsingContext): Call
ensureRealmForInitialEmptyDocument.
(WebKit::WebAutomationSession::scriptRealmCreated): Handle realm creation IPC
from WebProcess using RealmIdentifier.
(WebKit::WebAutomationSession::scriptRealmDestroyed): Handle realm destruction
IPC with activeRealms lookup to avoid race conditions.
(WebKit::WebAutomationSession::contextDestroyedForPage): Lookup realm ID before
notifying destruction.
(WebKit::WebAutomationSession::emitActiveBidiScriptRealmCreatedEvents):
Delegate to BidiScriptAgent.
* Source/WebKit/UIProcess/Automation/WebAutomationSession.h:
Added scriptRealmCreated, scriptRealmDestroyed, and
emitActiveBidiScriptRealmCreatedEvents handler declarations using
RealmIdentifier type.
* Source/WebKit/UIProcess/Automation/WebAutomationSession.messages.in:
Added ScriptRealmCreated and ScriptRealmDestroyed IPC messages with
RealmIdentifier parameter.
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.cpp:
(WebKit::WebDriverBidiProcessor::WebDriverBidiProcessor): Initialize
m_scriptDomainNotifier.
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.h:
Added scriptAgent() and scriptDomainNotifier() accessors.
Added m_scriptDomainNotifier member.
* Source/WebKit/UIProcess/Automation/protocol/BidiScript.json:
Added realmCreated and realmDestroyed event definitions.
* Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::WebAutomationSessionProxy::scriptRealmCreated): Forward to
WebAutomationSession via IPC with RealmIdentifier.
(WebKit::WebAutomationSessionProxy::scriptRealmDestroyed): Forward to
WebAutomationSession via IPC with RealmIdentifier.
(WebKit::WebAutomationSessionProxy::ensureRealmForInitialEmptyDocument): Force
JSWindowProxy creation using jsWindowProxy().
* Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h:
Added AutomationInstrumentationClient interface implementation.
Added ensureRealmForInitialEmptyDocument method.
Added m_frameToRealmIdentifier mapping.
* Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.messages.in:
Added EnsureRealmForInitialEmptyDocument IPC message.
* WebDriverTests/TestExpectations.json:
Updated test expectations for realm_created tests to match current
implementation.
Added missing test expectations for sandbox, workers, and iframe tests.
Canonical link: https://commits.webkit.org/310527@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications