Skip to content

[py][bidi]: implement bidi module - emulation #15819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: trunk
Choose a base branch
from

Conversation

navin772
Copy link
Member

@navin772 navin772 commented May 29, 2025

🔗 Related Issues

💥 What does this PR do?

Adds support for the emulation module in python bindings - https://w3c.github.io/webdriver-bidi/#module-emulation

🔧 Implementation Notes

Usage:

  1. From contexts:

    from selenium.webdriver.common.bidi.emulation import GeolocationCoordinates
    
    context_id = driver.current_window_handle
    coords = GeolocationCoordinates(45.5, -122.4194, accuracy=10.0)
    
    driver.emulation.set_geolocation_override(coordinates=coords, contexts=[context_id])
  2. From user_contexts:

    from selenium.webdriver.common.bidi.emulation import GeolocationCoordinates
    
    user_context = driver.browser.create_user_context()
    context_id = driver.browsing_context.create(type=WindowTypes.TAB, user_context=user_context)
    driver.switch_to.window(context_id)
    
    coords = GeolocationCoordinates(45.5, -122.4194, accuracy=10.0, altitude=100.2, altitude_accuracy=5.0, heading=183.2, speed=10.0)
    
    driver.emulation.set_geolocation_override(coordinates=coords, user_contexts=[user_context])

Important

Either user_contexts or contexts should be passed, both cannot coexist.

💡 Additional Considerations

The tests need the BiDi permissions module to grant the geolocation permission in order to fetch them.

Note

Currently, when the Error parameter is passed, it is returning an error invalid argument: Invalid input in "coordinates, hence the test is commented out for now.
It is fixed in chrome canary.

🔄 Types of changes

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

@selenium-ci selenium-ci added C-py Python Bindings B-devtools Includes everything BiDi or Chrome DevTools related labels May 29, 2025
@navin772
Copy link
Member Author

The tests require geolocation permission access which can be done once #15830 is merged.

@navin772 navin772 force-pushed the py-bidi-emulation branch from b8d7862 to 18eeca9 Compare May 30, 2025 18:48
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-py Python Bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants