Skip to content

Commit 77d269c

Browse files
Profiles API (#42)
* profiles docs! * docs: update code samples from OpenAPI * other notes * mesa knows english too --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 8c5ef58 commit 77d269c

7 files changed

Lines changed: 256 additions & 1 deletion

File tree

browsers/profiles.mdx

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
title: "Profiles"
3+
description: "Persist and reuse browser session state (cookies, local storage) across sessions"
4+
---
5+
6+
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.
7+
8+
## 1. Create a profile
9+
10+
The first step in using profiles is to create one, optionally giving it a meaningful `name` that is unique within your organization.
11+
12+
<CodeGroup>
13+
14+
```typescript Typescript/Javascript
15+
import { ConflictError, Kernel } from "@onkernel/sdk";
16+
17+
const kernel = new Kernel();
18+
19+
try {
20+
await kernel.profiles.create({ name: "profiles-demo" });
21+
} catch (err) {
22+
if (err instanceof ConflictError) {
23+
// Profile already exists; continue
24+
} else {
25+
throw err;
26+
}
27+
}
28+
```
29+
30+
```python Python
31+
from kernel import AsyncKernel, ConflictError
32+
33+
kernel = AsyncKernel()
34+
35+
try:
36+
await kernel.profiles.create(name="profiles-demo")
37+
except ConflictError:
38+
pass
39+
```
40+
41+
</CodeGroup>
42+
43+
## 2. Start a browser session using the profile and save changes
44+
45+
After creating the profile, you can reference it by its `name` or `id` when creating a browser.
46+
Set `save_changes` to true to persist any state created during this session back into the profile when the browser is closed.
47+
48+
<CodeGroup>
49+
50+
```typescript Typescript/Javascript
51+
const kernelBrowser = await kernel.browsers.create({
52+
profile: {
53+
name: "profiles-demo",
54+
// or
55+
// id: profile.id,
56+
save_changes: true,
57+
},
58+
});
59+
```
60+
61+
```python Python
62+
kernel_browser = await kernel.browsers.create(
63+
profile={
64+
"name": "profiles-demo",
65+
// or
66+
// "id": profile.id,
67+
"save_changes": True,
68+
}
69+
)
70+
```
71+
72+
</CodeGroup>
73+
74+
## 3. Use the browser, then close it to persist the state
75+
76+
After using a browser with `save_changes: true`, closing the browser will save cookies and local storage into the profile.
77+
78+
<CodeGroup>
79+
80+
```typescript Typescript/Javascript
81+
console.log("Live view:", kernelBrowser.browser_live_view_url);
82+
// Navigate and create login state ...
83+
await kernel.browsers.deleteByID(kernelBrowser.session_id);
84+
```
85+
86+
```python Python
87+
print("Live view:", kernel_browser.browser_live_view_url)
88+
# Navigate and create login state ...
89+
await kernel.browsers.delete_by_id(kernel_browser.session_id)
90+
```
91+
92+
</CodeGroup>
93+
94+
## 4. Start a new session with the saved profile (read-only)
95+
96+
Create another browser using the same profile name. Omitting `save_changes` leaves the stored profile untouched.
97+
98+
<CodeGroup>
99+
100+
```typescript Typescript/Javascript
101+
const kernelBrowser2 = await kernel.browsers.create({
102+
profile: { name: "profiles-demo" },
103+
});
104+
console.log("Live view:", kernelBrowser2.browser_live_view_url);
105+
```
106+
107+
```python Python
108+
kernel_browser2 = await kernel.browsers.create(
109+
profile={"name": "profiles-demo"}
110+
)
111+
print("Live view:", kernel_browser2.browser_live_view_url)
112+
```
113+
114+
</CodeGroup>
115+
116+
### Other ways to use profiles
117+
118+
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.
119+
120+
### Notes
121+
122+
- A profile's `name` must be unique within your organization.
123+
- Profiles store cookies and local storage. Start the session with `save_changes: true` to write changes back when the browser is closed.
124+
- To keep a profile immutable for a run, omit `save_changes` (default) when creating the browser.
125+
- You can spin up multiple browsers in parallel using the same profile.
126+
- Profile data is encrypted end to end using a per-organization key.

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"browsers/termination",
6363
"browsers/file-io",
6464
"browsers/live-view",
65-
"browsers/replays"
65+
"browsers/replays",
66+
"browsers/profiles"
6667
]
6768
},
6869
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
await client.profiles.delete('id_or_name');
10+
```
11+
12+
13+
```python Python
14+
from kernel import Kernel
15+
16+
client = Kernel(
17+
api_key="My API Key",
18+
)
19+
client.profiles.delete(
20+
"id_or_name",
21+
)
22+
```
23+
</CodeGroup>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const response = await client.profiles.download('id_or_name');
10+
11+
console.log(response);
12+
13+
const content = await response.blob();
14+
console.log(content);
15+
```
16+
17+
18+
```python Python
19+
from kernel import Kernel
20+
21+
client = Kernel(
22+
api_key="My API Key",
23+
)
24+
response = client.profiles.download(
25+
"id_or_name",
26+
)
27+
print(response)
28+
content = response.read()
29+
print(content)
30+
```
31+
</CodeGroup>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const profile = await client.profiles.retrieve('id_or_name');
10+
11+
console.log(profile.id);
12+
```
13+
14+
15+
```python Python
16+
from kernel import Kernel
17+
18+
client = Kernel(
19+
api_key="My API Key",
20+
)
21+
profile = client.profiles.retrieve(
22+
"id_or_name",
23+
)
24+
print(profile.id)
25+
```
26+
</CodeGroup>

snippets/openapi/get-profiles.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const profiles = await client.profiles.list();
10+
11+
console.log(profiles);
12+
```
13+
14+
15+
```python Python
16+
from kernel import Kernel
17+
18+
client = Kernel(
19+
api_key="My API Key",
20+
)
21+
profiles = client.profiles.list()
22+
print(profiles)
23+
```
24+
</CodeGroup>

snippets/openapi/post-profiles.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const profile = await client.profiles.create();
10+
11+
console.log(profile.id);
12+
```
13+
14+
15+
```python Python
16+
from kernel import Kernel
17+
18+
client = Kernel(
19+
api_key="My API Key",
20+
)
21+
profile = client.profiles.create()
22+
print(profile.id)
23+
```
24+
</CodeGroup>

0 commit comments

Comments
 (0)