Skip to content

Suggestion: Add grant_permissions() method to sb_cdp for permission handling via CDP #3814

Closed
@montovaneli

Description

@montovaneli

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 🙌

Metadata

Metadata

Assignees

Labels

UC Mode / CDP ModeUndetected Chromedriver Mode / CDP ModeenhancementMaking things better

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions