Skip to content

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

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

Closed
montovaneli opened this issue Jun 12, 2025 · 1 comment · Fixed by #3815
Closed
Assignees
Labels
enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@montovaneli
Copy link

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 🙌

@montovaneli montovaneli changed the title Suggestion: Add`grant_permissions() method to sb_cdp for permission handling via CDP Suggestion: Add grant_permissions() method to sb_cdp for permission handling via CDP Jun 12, 2025
@mdmintz mdmintz self-assigned this Jun 12, 2025
@mdmintz mdmintz added enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Jun 12, 2025
@mdmintz
Copy link
Member

mdmintz commented Jun 12, 2025

This was resolved in 4.39.4 - https://github.com/seleniumbase/SeleniumBase/releases/tag/v4.39.4

Note that the geolocation permission was already being set when changing geolocation.
See the examples:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants