Browsers
Persistence
Learn about reusing Kernel browsers across invocations
Persistence allows you to reuse a browser’s state, including cookies, session auth, cache, and any other state that lives on a browser. This can be used to minimize CAPTCHAs and login flows.
Reusing a browser
To reuse a browser over multiple invocations, specify persist
settings in the browsers.create()
method:
During runtime, Kernel will search for a browser with the specified id
:
- If a browser with the specified
id
is found, the existing browser will be provided to your app. - If abrowser with the specified
id
is not found, a new browser instance will be created and assigned the specifiedid
for future reuse.
The browser’s id
can be any string. You can set it to an identifier in your system to match it to a user, environment, website, or something else.
Notes about persistence
- If you don’t mark the browser for persistence when calling
browsers.create()
, the browser will be destroyed after the invocation completes. - Browsers can only maintain one connection at a time, so the invocation will fail if there is already a connection in progress.
- When reusing a browser, your app’s logic should account for scenarios where cookies are present (for example, skip login details if already authenticated) as well as when they’re not (in case the cookies have expired).
- Most websites’ authentication schemes set TTLs. Kernel’s browser persistence helps you reuse the browser’s cookies, but they’re only valid as long as the cookies’ TTL.
See the CLI reference for full details.