Skip to content

[py] Implement high level APIs for script#17371

Merged
AutomatedTester merged 5 commits into
trunkfrom
cdp-to-bidi
Apr 27, 2026
Merged

[py] Implement high level APIs for script#17371
AutomatedTester merged 5 commits into
trunkfrom
cdp-to-bidi

Conversation

@AutomatedTester

Copy link
Copy Markdown
Member

🔗 Related Issues

💥 What does this PR do?

[py] Implement high level APIs for script for bidi and deprecate the CDP versions

🔧 Implementation Notes

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s):copilot
    • What was generated:
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

🔄 Types of changes

  • New feature (non-breaking change which adds functionality and tests!)

This is finishing the python part of #13992. It adds DOM Mutation
and sets the CDP version to be deprecated as part of the longer term
move towards Webdriver-Bidi.
Copilot AI review requested due to automatic review settings April 22, 2026 13:58
@selenium-ci selenium-ci added C-py Python Bindings B-build Includes scripting, bazel and CI integrations labels Apr 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a new high-level Python BiDi Script API for DOM mutation handling, and deprecates legacy CDP-based “pinned script” and log listener APIs in favor of BiDi equivalents.

Changes:

  • Add driver.script.add_dom_mutation_handler() / remove_dom_mutation_handler() (plus DomMutation event type) via the BiDi codegen enhancements manifest.
  • Deprecate legacy RemoteWebDriver.pin_script(), unpin(), and get_pinned_scripts(), and deprecate CDP-based log listeners with guidance toward BiDi Script handlers.
  • Add test coverage for the new DOM mutation handler and wire the new JS preload helper into Bazel/package data.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
py/test/selenium/webdriver/common/bidi_script_tests.py Adds tests for BiDi DOM mutation handler registration/removal and multi-handler behavior.
py/selenium/webdriver/remote/webdriver.py Marks script pinning APIs deprecated and emits DeprecationWarning with migration guidance.
py/selenium/webdriver/common/log.py Deprecates CDP-based log/mutation listeners and suppresses internal deprecation warnings from legacy pinning calls.
py/private/bidi_enhancements_manifest.py Adds DomMutation dataclass and mutation handler subscription/unsubscription logic using BiDi script.message + preload scripts.
py/BUILD.bazel Ships bidi-mutation-listener.js as Python package data for the BiDi module.
javascript/bidi-support/BUILD.bazel Exposes bidi-mutation-listener.js to the Python build via Bazel visibility/exports.

Comment thread py/private/bidi_enhancements_manifest.py Outdated
Comment thread py/private/bidi_enhancements_manifest.py Outdated
Comment thread py/private/bidi_enhancements_manifest.py Outdated
Comment thread py/test/selenium/webdriver/common/bidi_script_tests.py Outdated
Comment thread py/test/selenium/webdriver/common/bidi_script_tests.py Outdated
AutomatedTester and others added 2 commits April 22, 2026 15:56
- Cache the mutation preload script ID and add it only once per Script
  instance to prevent duplicate MutationObservers accumulating on each
  add_dom_mutation_handler() call
- Also invoke the preload script immediately in the current browsing
  context (call_function) since preload scripts only run on future
  document creations
- Move preload script registration inside the mutation lock to prevent
  races when two handlers are registered concurrently
- Remove find_elements() call from the background event callback
  (WebDriver is not thread-safe); replace DomMutation.element field
  with element_id (the raw data-__webdriver_id string) that callers
  can use to locate the element on the main thread
- Relax cross-browser fragile test assertions on old_value/current_value
- Replace time.sleep(1) with WebDriverWait until the DOM mutation
  completes, making the no-callback assertion reliable

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 22, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread py/private/bidi_enhancements_manifest.py Outdated
Comment thread py/private/bidi_enhancements_manifest.py Outdated
Comment thread py/private/bidi_enhancements_manifest.py
- Use a namespaced UUID channel name (selenium.domMutation.<uuid>)
  instead of the literal 'channel_name' to avoid collisions with
  user preload scripts or other BiDi channel users
- Move add_callback registration to after preload script and
  session.subscribe setup so a failed setup does not leak a
  dangling callback
- Remove the preload script (remove_preload_script) and clear
  _mutation_preload_script_id when the last mutation handler is
  removed, cleaning up the MutationObserver for future navigations
- Relax old_value assertion in test: Firefox BiDi returns null for
  the oldValue of style attribute mutations so skip that check when
  old_value is None rather than failing the test on Firefox

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AutomatedTester AutomatedTester merged commit 0275fbd into trunk Apr 27, 2026
55 of 56 checks passed
@AutomatedTester AutomatedTester deleted the cdp-to-bidi branch April 27, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants