Closed
Description
Suggestion: Add grant_permissions()
method to sb_cdp
for permission handling via CDP
Hi there 👋
I'm using seleniumbase
with the sb_cdp
mode (via activate_cdp_mode) and would like to grant permissions (such as geolocation) via the Chrome DevTools Protocol. The Browser.grantPermissions
endpoint would allow for more flexible test setups, especially for location-based features.
💡 Suggested Implementation
In undetected -> cdp_driver -> browser
:
async def grant_permissions(self, permission_types: list[str] = ["geolocation"], origin: str = None):
"""
Allowed permssion_type values: ar, audioCapture, automaticFullscreen, backgroundFetch, backgroundSync, cameraPanTiltZoom, capturedSurfaceControl, clipboardReadWrite,
clipboardSanitizedWrite, displayCapture, durableStorage, geolocation, handTracking, idleDetection, keyboardLock, localFonts, localNetworkAccess, midi, midiSysex, nfc, notifications,
paymentHandler, periodicBackgroundSync, pointerLock, protectedMediaIdentifier, sensors, smartCard, speakerSelection, storageAccess, topLevelStorageAccess,
videoCapture, vr, wakeLockScreen, wakeLockSystem, webAppInstallation, webPrinting, windowManagement
"""
await self.connection.send(cdp.browser.grant_permissions(permission_types, origin=origin))
In core -> sb_cdp
:
def grant_permissions(self, permission_types: list[str] = ["geolocation"], origin: str = None):
"""Grant permissions to the current page."""
driver = self.driver
if hasattr(driver, "cdp_base"):
driver = driver.cdp_base
return self.loop.run_until_complete(
driver.grant_permissions(permission_types, origin)
)
This would be especially useful for tests involving location access or other permission-based browser features.
I've already implemented these changes locally and they’ve been working very well in my tests so far.
Thanks for the great project 🙌