From 63911dfffea2d36fc54ae0a7d35730f0ec635e16 Mon Sep 17 00:00:00 2001 From: Rafael Garcia Date: Thu, 4 Sep 2025 15:36:53 -0400 Subject: [PATCH 1/4] profiles docs! --- browsers/profiles.mdx | 121 ++++++++++++++++++++++++++++++++++++++++++ docs.json | 3 +- 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 browsers/profiles.mdx diff --git a/browsers/profiles.mdx b/browsers/profiles.mdx new file mode 100644 index 0000000..9df825e --- /dev/null +++ b/browsers/profiles.mdx @@ -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. + + + +```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 +``` + + + +## 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. + + + +```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, + } +) +``` + + + +## 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. + + + +```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) +``` + + + +## 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. + + + +```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) +``` + + + +### 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. diff --git a/docs.json b/docs.json index 1e5d4a6..4a1019b 100644 --- a/docs.json +++ b/docs.json @@ -62,7 +62,8 @@ "browsers/termination", "browsers/file-io", "browsers/live-view", - "browsers/replays" + "browsers/replays", + "browsers/profiles" ] }, { From 8397a887f17f71d475bab7500254afca820715df Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 4 Sep 2025 19:37:11 +0000 Subject: [PATCH 2/4] docs: update code samples from OpenAPI --- .../openapi/delete-profiles-id_or_name.mdx | 23 ++++++++++++++ .../get-profiles-id_or_name-download.mdx | 31 +++++++++++++++++++ snippets/openapi/get-profiles-id_or_name.mdx | 26 ++++++++++++++++ snippets/openapi/get-profiles.mdx | 24 ++++++++++++++ snippets/openapi/post-profiles.mdx | 24 ++++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 snippets/openapi/delete-profiles-id_or_name.mdx create mode 100644 snippets/openapi/get-profiles-id_or_name-download.mdx create mode 100644 snippets/openapi/get-profiles-id_or_name.mdx create mode 100644 snippets/openapi/get-profiles.mdx create mode 100644 snippets/openapi/post-profiles.mdx diff --git a/snippets/openapi/delete-profiles-id_or_name.mdx b/snippets/openapi/delete-profiles-id_or_name.mdx new file mode 100644 index 0000000..f114479 --- /dev/null +++ b/snippets/openapi/delete-profiles-id_or_name.mdx @@ -0,0 +1,23 @@ + +```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", +) +``` + diff --git a/snippets/openapi/get-profiles-id_or_name-download.mdx b/snippets/openapi/get-profiles-id_or_name-download.mdx new file mode 100644 index 0000000..c6307bd --- /dev/null +++ b/snippets/openapi/get-profiles-id_or_name-download.mdx @@ -0,0 +1,31 @@ + +```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) +``` + diff --git a/snippets/openapi/get-profiles-id_or_name.mdx b/snippets/openapi/get-profiles-id_or_name.mdx new file mode 100644 index 0000000..4941e43 --- /dev/null +++ b/snippets/openapi/get-profiles-id_or_name.mdx @@ -0,0 +1,26 @@ + +```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) +``` + diff --git a/snippets/openapi/get-profiles.mdx b/snippets/openapi/get-profiles.mdx new file mode 100644 index 0000000..4dfc0ae --- /dev/null +++ b/snippets/openapi/get-profiles.mdx @@ -0,0 +1,24 @@ + +```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) +``` + diff --git a/snippets/openapi/post-profiles.mdx b/snippets/openapi/post-profiles.mdx new file mode 100644 index 0000000..5f13419 --- /dev/null +++ b/snippets/openapi/post-profiles.mdx @@ -0,0 +1,24 @@ + +```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) +``` + From 5f7a2af58a60d277fa9540a3b9415c4d5ebbd5fa Mon Sep 17 00:00:00 2001 From: Rafael Garcia Date: Thu, 4 Sep 2025 15:43:58 -0400 Subject: [PATCH 3/4] other notes --- browsers/profiles.mdx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/browsers/profiles.mdx b/browsers/profiles.mdx index 9df825e..5a6a95b 100644 --- a/browsers/profiles.mdx +++ b/browsers/profiles.mdx @@ -113,9 +113,14 @@ print("Live view:", kernel_browser2.browser_live_view_url) +### Other ways to use profiles + +The API and SDKs support listing, deleting, and downloading profile data as JSON. See the [API reference](/api-reference/profiles/list-profiles) for more details. + ### 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. +- Profile data is encrypted end to end using a per-organization key. From f280277af65d9294771cd592aee3104751070185 Mon Sep 17 00:00:00 2001 From: Rafael Garcia Date: Thu, 4 Sep 2025 15:46:33 -0400 Subject: [PATCH 4/4] mesa knows english too --- browsers/profiles.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browsers/profiles.mdx b/browsers/profiles.mdx index 5a6a95b..30961a0 100644 --- a/browsers/profiles.mdx +++ b/browsers/profiles.mdx @@ -42,7 +42,7 @@ except ConflictError: ## 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. +After creating the profile, you can reference it by its `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.