Skip to main content

Overview

Browser contexts provide isolated browser environments. This guide covers advanced context features like permissions, geolocation, timezone emulation, offline mode, and more.

Permissions

Grant or deny browser permissions for specific origins to test permission-dependent features.

Available Permissions

Allow access to device location.
Allow access to MIDI devices.
Allow showing notifications.
Allow access to camera.
Allow access to microphone.
Allow reading from clipboard.
Allow writing to clipboard.
Allow registering payment handlers.

Geolocation

Emulate device geolocation to test location-based features.

Offline Mode

Simulate offline network conditions to test application behavior without connectivity.
Offline Mode

Timezone Emulation

Emulate different timezones to test time-sensitive features.
Timezone Configuration

Locale and Language

Emulate different locales and languages for internationalization testing.

HTTP Authentication

Provide HTTP authentication credentials for protected resources.
HTTP Credentials

Extra HTTP Headers

Add custom HTTP headers to all requests in the context.
Custom Headers

Storage State

Save and restore browser context state including cookies and local storage.

Service Workers

Access and interact with service workers in the context.
Service Workers

Best Practices

Isolation

Use separate contexts for tests requiring different browser states. Each context is completely isolated.

Performance

Reuse contexts when possible, but create new ones when state needs to be reset completely.

Permissions

Always grant necessary permissions before navigating to pages that require them.

Cleanup

Contexts are automatically closed, but explicitly close them when done for clarity.

Browser Context Basics

Learn the fundamentals of browser contexts

Authentication

Advanced authentication patterns