Storage State
Storage state allows you to load cookies and local storage into the browser context.Using User Data Directory
Start with a user data directory to persist all browser data between sessions:- Cookies
- Local storage
- Session storage
- IndexedDB
- Cache
- Extensions
Using Storage State File
Start with a storage state file to load cookies and local storage into an isolated browser context:Page Initialization
Init Page Script
Use--init-page to point to a TypeScript file that will be evaluated on the Playwright page object. This allows you to run arbitrary code to set up the page.
Example: Set geolocation and viewport
init-page.ts
Init Script
Use--init-script to point to a JavaScript file that will be added as an initialization script. The script will be evaluated in every page before any of the page’s scripts.
This is useful for:
- Overriding browser APIs
- Setting up the environment
- Injecting custom global variables
init-script.js

