Overview
As your number of sessions grows, attaching a customizable label to your sessions helps you organize and access them based on your specific needs. For this, we created Session Metadata. Session metadata can be attached to a session and later be queried as part of our List Sessions API.Why Use Metadata?
Consider running automated tests across multiple browser sessions. Without metadata, you’d struggle to track which session belongs to which test run. With metadata, you can attach a “run ID” to each session and easily query them later. Similarly, you might want to track the status of downloads or associate sessions with specific projects or teams. Each of these are possible with metadata.Structure
Session metadata is a simple but flexible structure:- All metadata is a customizable JSON object
- Your JSON object must be under 512 characters
- Data is organized in a nested structure using fields (no arrays supported yet)
- Only string values are supported for querying (convert numbers and booleans to strings)
- Metadata persists throughout the entire session lifecycle
Attach Metadata to a Session
Pass theuserMetadata parameter when creating a session via the Create Session endpoint. This metadata can be any JSON-serializable object.
Below is an example that attaches {"env": "staging"} to a session.
- Node.js
- Python
Query Sessions by Metadata
Pass a query string to theq parameter in List Sessions to filter sessions by metadata. The query string format is always user_metadata['path']['to']['field']:'value'.
Below is an example that finds all sessions with {"env": "staging"}.
- Node.js
- Python
- cURL
[].
Best Practices
Use descriptive, consistent naming and keep your metadata structure shallow and intuitive. Tip: Need to query numbers or booleans? Convert them to strings:Limitations
- JSON object must be under 512 characters (think
JSON.stringifyand measuring the resulting length) - Only field queries are supported (no array querying)
- Only string equality checks are available
- Only the
user_metadatabase is supported