Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: bb48b7c44ce67a4f1bf5aedab6e08cef784dbcc4
      
https://github.com/WebKit/WebKit/commit/bb48b7c44ce67a4f1bf5aedab6e08cef784dbcc4
  Author: Serge Deh <[email protected]>
  Date:   2026-07-08 (Wed, 08 Jul 2026)

  Changed paths:
    M Source/WebKit/UIProcess/Automation/BidiBrowsingContextAgent.cpp
    M Source/WebKit/UIProcess/Automation/BidiBrowsingContextAgent.h
    M Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.cpp
    M Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.h
    M Source/WebKit/UIProcess/Automation/protocol/BidiBrowsingContext.json
    M WebDriverTests/TestExpectations.json

  Log Message:
  -----------
  [WebDriver BiDi] Implement browsingContext.locateNodes with CSS selector 
support
https://bugs.webkit.org/show_bug.cgi?id=288329

Reviewed by BJ Burg.

This patch implements the browsingContext.locateNodes command with initial
support for CSS selector-based node location. The implementation includes
protocol definitions, parameter validation, DOM query execution, and
RemoteValue serialization for found nodes.

This patch also extracts shared serializationOptions validation to a reusable
helper and fixes a critical security issue where user-provided functions could
access WebAutomationSessionProxy internals via 'this' binding.

Key implementation details:
- Uses extractBrowsingContextHandles() to support both top-level and iframe 
contexts
- Inlines CSS selector logic directly in C++ string since _execute uses 
apply(null, ...)
- Returns actual DOM nodes from JavaScript for proper handle generation via 
WebKit's
  node serialization (_createNodeHandle/_identifierForNode in 
WebAutomationSessionProxy)
- Throws InvalidSelector error (not generic Error) for proper BiDi error mapping
- Accepts serializationOptions parameter per spec (validation only, not yet 
applied)
- Shared validation helper enables reuse across multiple BiDi commands

* Source/WebKit/UIProcess/Automation/protocol/BidiBrowsingContext.json:
Added Locator and LocatorType type definitions, and the locateNodes
command definition. Currently supports CSS selectors, with additional
locator types (xpath, innerText, accessibility) to be added in follow-up 
patches.
Added serializationOptions parameter to match BiDi spec.

* Source/WebKit/UIProcess/Automation/BidiBrowsingContextAgent.h:
Added locateNodes method declaration with serializationOptions parameter.

* Source/WebKit/UIProcess/Automation/BidiBrowsingContextAgent.cpp:
(WebKit::extractNodeFromLocateResult): Helper to parse [node, metadata] tuples.
(WebKit::parseLocateNodesResult): Helper to parse JavaScript query results.
(WebKit::BidiBrowsingContextAgent::locateNodes):
Implemented locateNodes command with CSS selector support. Uses shared
validateSerializationOptions() helper and inlines JavaScript logic since
wrapper functions have this=null and cannot access proxy methods.

* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.h:
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.cpp:
(WebKit::WebDriverBidiProcessor::validateSerializationOptions):
Added static helper to validate BiDi serializationOptions parameter 
(maxDomDepth,
maxObjectDepth, includeShadowTree). Returns CommandResult<void> for consistency.
Shared across multiple commands: browsingContext.locateNodes, 
script.callFunction,
script.evaluate.

* Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.js:
(AutomationSessionProxy.prototype._execute):
Changed functionValue.apply(this, ...) to apply(null, ...) to prevent
user-provided functions from accessing proxy internals via 'this' binding.
This secures ALL user function execution (script.evaluate, script.callFunction).

* WebDriverTests/TestExpectations.json:
Enabled browsingContext.locateNodes tests for CSS selector locator type.

Support for startNodes parameter, serializationOptions application, and 
additional
locator types will be added in subsequent patches.

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



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

Reply via email to