-
Notifications
You must be signed in to change notification settings - Fork 6
Profiles API #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rgarcia
merged 4 commits into
main
from
raf/kernel-229-feature-request-api-to-save-browser-contexts
Sep 4, 2025
Merged
Profiles API #42
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| --- | ||
| title: "Profiles" | ||
| description: "Persist and reuse browser session state (cookies, local storage) across sessions" | ||
| --- | ||
|
|
||
| Kernel Profiles let you capture browser state created during a session — cookies and local storage — and reuse it in later sessions. This is useful for persisting login state or other site preferences across runs. | ||
|
|
||
| ## 1. Create a profile | ||
|
|
||
| The first step in using profiles is to create one, optionally giving it a meaningful `name` that is unique within your organization. | ||
|
|
||
| <CodeGroup> | ||
|
|
||
| ```typescript Typescript/Javascript | ||
| import { ConflictError, Kernel } from "@onkernel/sdk"; | ||
|
|
||
| const kernel = new Kernel(); | ||
|
|
||
| try { | ||
| await kernel.profiles.create({ name: "profiles-demo" }); | ||
| } catch (err) { | ||
| if (err instanceof ConflictError) { | ||
| // Profile already exists; continue | ||
| } else { | ||
| throw err; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```python Python | ||
| from kernel import AsyncKernel, ConflictError | ||
|
|
||
| kernel = AsyncKernel() | ||
|
|
||
| try: | ||
| await kernel.profiles.create(name="profiles-demo") | ||
| except ConflictError: | ||
| pass | ||
| ``` | ||
|
|
||
| </CodeGroup> | ||
|
|
||
| ## 2. Start a browser session using the profile and save changes | ||
|
|
||
| After creating the profile, you can reference it by it's `name` or `id` when creating a browser. | ||
| Set `save_changes` to true to persist any state created during this session back into the profile when the browser is closed. | ||
|
|
||
| <CodeGroup> | ||
|
|
||
| ```typescript Typescript/Javascript | ||
| const kernelBrowser = await kernel.browsers.create({ | ||
| profile: { | ||
| name: "profiles-demo", | ||
| // or | ||
| // id: profile.id, | ||
| save_changes: true, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ```python Python | ||
| kernel_browser = await kernel.browsers.create( | ||
| profile={ | ||
| "name": "profiles-demo", | ||
| // or | ||
| // "id": profile.id, | ||
| "save_changes": True, | ||
| } | ||
| ) | ||
| ``` | ||
|
|
||
| </CodeGroup> | ||
|
|
||
| ## 3. Use the browser, then close it to persist the state | ||
|
|
||
| After using a browser with `save_changes: true`, closing the browser will save cookies and local storage into the profile. | ||
|
|
||
| <CodeGroup> | ||
|
|
||
| ```typescript Typescript/Javascript | ||
| console.log("Live view:", kernelBrowser.browser_live_view_url); | ||
| // Navigate and create login state ... | ||
| await kernel.browsers.deleteByID(kernelBrowser.session_id); | ||
| ``` | ||
|
|
||
| ```python Python | ||
| print("Live view:", kernel_browser.browser_live_view_url) | ||
| # Navigate and create login state ... | ||
| await kernel.browsers.delete_by_id(kernel_browser.session_id) | ||
| ``` | ||
|
|
||
| </CodeGroup> | ||
|
|
||
| ## 4. Start a new session with the saved profile (read-only) | ||
|
|
||
| Create another browser using the same profile name. Omitting `save_changes` leaves the stored profile untouched. | ||
|
|
||
| <CodeGroup> | ||
|
|
||
| ```typescript Typescript/Javascript | ||
| const kernelBrowser2 = await kernel.browsers.create({ | ||
| profile: { name: "profiles-demo" }, | ||
| }); | ||
| console.log("Live view:", kernelBrowser2.browser_live_view_url); | ||
| ``` | ||
|
|
||
| ```python Python | ||
| kernel_browser2 = await kernel.browsers.create( | ||
| profile={"name": "profiles-demo"} | ||
| ) | ||
| print("Live view:", kernel_browser2.browser_live_view_url) | ||
| ``` | ||
|
|
||
| </CodeGroup> | ||
|
|
||
| ### Notes | ||
|
|
||
| - A profile's `name` must be unique within your organization. | ||
| - Profiles store cookies and local storage. Start the session with `save_changes: true` to write changes back when the browser is closed. | ||
| - To keep a profile immutable for a run, omit `save_changes` (default) when creating the browser. | ||
| - You can spin up multiple browsers in parallel using the same profile. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <CodeGroup> | ||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| await client.profiles.delete('id_or_name'); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| client.profiles.delete( | ||
| "id_or_name", | ||
| ) | ||
| ``` | ||
| </CodeGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <CodeGroup> | ||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| const response = await client.profiles.download('id_or_name'); | ||
|
|
||
| console.log(response); | ||
|
|
||
| const content = await response.blob(); | ||
| console.log(content); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| response = client.profiles.download( | ||
| "id_or_name", | ||
| ) | ||
| print(response) | ||
| content = response.read() | ||
| print(content) | ||
| ``` | ||
| </CodeGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <CodeGroup> | ||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| const profile = await client.profiles.retrieve('id_or_name'); | ||
|
|
||
| console.log(profile.id); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| profile = client.profiles.retrieve( | ||
| "id_or_name", | ||
| ) | ||
| print(profile.id) | ||
| ``` | ||
| </CodeGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <CodeGroup> | ||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| const profiles = await client.profiles.list(); | ||
|
|
||
| console.log(profiles); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| profiles = client.profiles.list() | ||
| print(profiles) | ||
| ``` | ||
| </CodeGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <CodeGroup> | ||
| ```typescript Typescript/Javascript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const client = new Kernel({ | ||
| apiKey: 'My API Key', | ||
| }); | ||
|
|
||
| const profile = await client.profiles.create(); | ||
|
|
||
| console.log(profile.id); | ||
| ``` | ||
|
|
||
|
|
||
| ```python Python | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel( | ||
| api_key="My API Key", | ||
| ) | ||
| profile = client.profiles.create() | ||
| print(profile.id) | ||
| ``` | ||
| </CodeGroup> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.