Skip to content

[js][bidi] Type vendor-declared BiDi fields instead of making extended types extensible - #18335

Merged
pujagani merged 1 commit into
SeleniumHQ:trunkfrom
pujagani:vendor-fields-js
Nov 18, 2026
Merged

pujagani merged 1 commit into
SeleniumHQ:trunkfrom
pujagani:vendor-fields-js

Conversation

@pujagani

Copy link
Copy Markdown
Contributor

🔗 Related Issues

Addresses the JavaScript part of #18184. Follows the design agreed there, already implemented for Ruby (#18190) and Java (#18233).

💥 What does this PR do?

Firefox's vendor CDDL adds a few fields to some spec types, for example moz:name and moz:scope on browsingContext.Info. The JS BiDi generator handled this by marking those types extensible, so they accepted and sent any field, not just the vendor ones. That breaks ADR 17786.

This PR types the vendor fields instead:

  • Sent: the shared GetTreeParameters and InstallParameters stay closed. Vendor fields only exist on MozGetTreeParameters and MozInstallParameters, used by MozBrowsingContext.getTree and MozWebExtension.install.
  • Received: browsingContext.Info gets typed, optional mozName and mozScope. Other browsers leave them empty. Any other unknown field is warned about and dropped.

Example:

const { contexts } = await browsingContext.getTree({})
contexts[0].mozScope                                      // 'content' (was contexts[0]['moz:scope'])

await browsingContext.getTree({ 'moz:scope': 'chrome' })  // now throws: not a shared field
await mozBrowsingContext.getTree({ scope: 'chrome' })     // the way to send it

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s): Claude Code
    • What was generated: the generator change and the new tests in vendor_test.js
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

  • Breaking for JS users of the generated Firefox data: info['moz:name'] / info['moz:scope'] become info.mozName / info.mozScope, matching Java and Ruby naming. The shared classes also stop sending undeclared fields. This is okay since it was decided in the low-level ADR that low-level APIs stays publicly reachable but is not governed by the deprecation policy.

🔄 Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)

@selenium-ci

Copy link
Copy Markdown
Member

/agentic_describe

@selenium-ci

Copy link
Copy Markdown
Member

/agentic_review

@selenium-ci selenium-ci added C-nodejs JavaScript Bindings B-devtools Includes everything BiDi or Chrome DevTools related labels Nov 18, 2026
@qodo-code-review

qodo-code-review Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Type declared vendor fields in JavaScript BiDi records

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Type declared vendor fields on received BiDi records instead of accepting arbitrary fields.
• Keep shared command parameters closed; send vendor parameters only through vendor classes.
• Test field validation, optional received fields, event parsing, and unknown-field warnings.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed generator and the inspected record deserializer jointly implement one bounded binding behavior: generated shared records receive protocol records and map declared vendor wire fields into typed JavaScript properties.
  • Session capability records and browsing-context records are distinct record locations but remain within the same generated BiDi binding integration; the change does not establish an independent deployment or business scope.
Sources

javascript/selenium-webdriver/generate_bidi.mjs[276-278]

  foldVendorExtensions(schema)

  const typesByDomain = groupTypesByDomain(schema.types)
Behavioral complexity 🟡 Medium 🧩 Multiple interactions

  • Before, vendor extensions were handled by marking extended shared types extensible, which preserved undeclared wire fields without typed folding.
  • After, the generator distinguishes extensible records, command-parameter records, and other records; it checks wire/name collisions, makes folded fields optional, transforms names, mutates the shared schema, and recursively collects referenced vendor types.
  • The new correctness conditions are that received vendor fields are typed and mapped consistently across shared classes, command parameters remain vendor-variant-only, and mixed spec/vendor schema states do not collide.
  • These are compatibility and interacting-branch conditions, not merely routine reuse of existing validation infrastructure.
Potential damage 🟡 Medium 🩹 Recoverable

  • A wrong generated record shape can cause BiDi responses or events to fail validation or expose incorrect data, producing a recoverable client capability degradation rather than persistent corruption.
  • Reverting/regenerating the binding restores code behavior; any already-failed client operation must be retried, but no persistent protocol state is changed.
  • Equal business importance is assumed because no Business Criticality Map was supplied.
  • Recoverable by correcting or reverting the generator and regenerating the JavaScript BiDi artifacts; failures already observed by callers require retry.
  • No automatic state repair or external-effect compensation is implicated.
Assessed commit 4b1e7e9 > Snapshot assessment: the current PR revision could not be verified.
Diagram

graph TD
  A["Vendor CDDL"] --> B["Projected schema"] --> C{"Command params?"}
  C -->|Yes| D["Vendor parameters"] --> F["Outbound validation"]
  C -->|No| E["Shared record"] --> G["Inbound parsing"]
Loading
High-Level Assessment

The split between vendor-only sent parameters and shared received records fits the existing generator and runtime parsing model. Keeping received fields only on vendor classes would require separate parsing for results that the shared class also receives; leaving records extensible would continue accepting undeclared fields.

Files changed (2) +131 / -24

Bug fix (1) +38 / -9
generate_bidi.mjsFold declared vendor fields into received record types +38/-9

Fold declared vendor fields into received record types

• Replaces blanket extensibility for vendor-extended types with optional, named fields on shared received records, including referenced vendor types. Leaves command parameters to existing vendor-specific variants and checks for invalid extensions and field collisions.

javascript/selenium-webdriver/generate_bidi.mjs

Tests (1) +93 / -15
vendor_test.jsCover vendor field parsing and closed command parameters +93/-15

Cover vendor field parsing and closed command parameters

• Tests typed vendor fields on shared results and events, their absence when not sent, invalid values, and warnings for undeclared received fields. Also verifies that shared commands reject vendor parameters and vendor variants reject undeclared or wire-key inputs.

javascript/selenium-webdriver/test/bidi/vendor_test.js

@pujagani
pujagani merged commit c29d42a into SeleniumHQ:trunk Nov 18, 2026
32 checks passed
This was referenced Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-devtools Includes everything BiDi or Chrome DevTools related C-nodejs JavaScript Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants