What is a transport?
A transport is a reusable network layer handle that owns:- Transport-level settings like
proxy,browser,os, andinsecure - Reusable network context used by requests and sessions
When should I use Transport vs Sessions?
Use the simplest tool that matches your needs:| You need… | Use | Why |
|---|---|---|
| One-off request with maximum isolation | Ephemeral fetch() | Separate request context per call |
| Multi-step flow with cookies (login, checkout, etc.) | Sessions | Shared session context across requests |
| Reuse a single proxy across many requests | Transport | You create it once and reuse it |
| Separate cookie jars with shared transport config | Sessions + shared Transport | Sessions stay isolated while sharing transport settings |
Creating and reusing a transport
A common pattern is one transport per proxy, reused across many requests:Using Transport with sessions
Sessions are the right default for cookie-based flows. If you want multiple sessions (separate cookies) to share a single transport context (same proxy/emulation), pass the same transport per request:Ownership rules (important)
When you pass atransport, it owns browser, os, proxy, and insecure.
- Do not also set
browser,os,proxy, orinsecureon the request. - Prefer creating a separate transport if you need different settings.
Lifecycle
Always close transports you create:- Close when you no longer need the transport:
await transport.close() - After closing, the transport cannot be used again
Related
- API details:
createTransport() - Cookie flows: Sessions