From 382e0435dbaf01434e73bc4ab6148d6657d6c502 Mon Sep 17 00:00:00 2001 From: Mason Williams Date: Sun, 30 Nov 2025 15:38:53 -0500 Subject: [PATCH 1/2] refactor(browser): update browser creation params --- templates/python/advanced-sample/main.py | 1 - templates/python/sample-app/main.py | 18 ++++++++--------- templates/typescript/advanced-sample/index.ts | 3 --- templates/typescript/sample-app/index.ts | 20 +++++++++---------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/templates/python/advanced-sample/main.py b/templates/python/advanced-sample/main.py index 17994cc..32dcec2 100644 --- a/templates/python/advanced-sample/main.py +++ b/templates/python/advanced-sample/main.py @@ -25,7 +25,6 @@ async def test_captcha_solver(ctx: kernel.KernelContext) -> None: kernel_browser = client.browsers.create( invocation_id=ctx.invocation_id, stealth=True, - persistence={"id": "captcha-solver"} ) async with async_playwright() as playwright: diff --git a/templates/python/sample-app/main.py b/templates/python/sample-app/main.py index 15587b0..63fd2bb 100644 --- a/templates/python/sample-app/main.py +++ b/templates/python/sample-app/main.py @@ -66,9 +66,9 @@ async def get_page_title(ctx: kernel.KernelContext, input_data: PageTitleInput) """ -Example app that instantiates a persisted Kernel browser that can be reused across invocations +Example app that creates a long-running Kernel browser for manual testing Invoke this action to test Kernel browsers manually with our browser live view -https://onkernel.com/docs/browsers/persistence +https://onkernel.com/docs/browsers/live-view Args: ctx: Kernel context containing invocation information Returns: @@ -76,20 +76,20 @@ async def get_page_title(ctx: kernel.KernelContext, input_data: PageTitleInput) Invoke this via CLI: kernel login # or: export KERNEL_API_KEY= kernel deploy main.py # If you haven't already deployed this app - kernel invoke python-basic create-persisted-browser + kernel invoke python-basic create-browser-for-testing kernel logs python-basic -f # Open in separate tab """ -class CreatePersistedBrowserOutput(TypedDict): +class CreateBrowserForTestingOutput(TypedDict): browser_live_view_url: str -@app.action("create-persisted-browser") -async def create_persisted_browser(ctx: kernel.KernelContext) -> CreatePersistedBrowserOutput: +@app.action("create-browser-for-testing") +async def create_browser_for_testing(ctx: kernel.KernelContext) -> CreateBrowserForTestingOutput: kernel_browser = client.browsers.create( invocation_id=ctx.invocation_id, - persistence={"id": "persisted-browser"}, - stealth=True, # Turns on residential proxy & auto-CAPTCHA solver + stealth=True, + timeout_seconds=3600, # Keep browser alive for 1 hour ) return { "browser_live_view_url": kernel_browser.browser_live_view_url, - } \ No newline at end of file + } diff --git a/templates/typescript/advanced-sample/index.ts b/templates/typescript/advanced-sample/index.ts index 86bd531..85d392b 100644 --- a/templates/typescript/advanced-sample/index.ts +++ b/templates/typescript/advanced-sample/index.ts @@ -24,9 +24,6 @@ app.action("test-captcha-solver", async (ctx: KernelContext): Promise => { const kernelBrowser = await kernel.browsers.create({ invocation_id: ctx.invocation_id, stealth: true, - persistence: { - id: "captcha-solver", - }, }); const browser = await chromium.connectOverCDP(kernelBrowser.cdp_ws_url); diff --git a/templates/typescript/sample-app/index.ts b/templates/typescript/sample-app/index.ts index 09fcaa0..8012b48 100644 --- a/templates/typescript/sample-app/index.ts +++ b/templates/typescript/sample-app/index.ts @@ -76,9 +76,9 @@ app.action( ); /** - * Example app that instantiates a persisted Kernel browser that can be reused across invocations + * Example app that creates a long-running Kernel browser for manual testing * Invoke this action to test Kernel browsers manually with our browser live view - * https://onkernel.com/docs/browsers/persistence + * https://onkernel.com/docs/browsers/live-view * Args: * ctx: Kernel context containing invocation information * Returns: @@ -86,21 +86,19 @@ app.action( * Invoke this via CLI: * kernel login # or: export KERNEL_API_KEY= * kernel deploy index.ts # If you haven't already deployed this app - * kernel invoke ts-basic create-persisted-browser + * kernel invoke ts-basic create-browser-for-testing * kernel logs ts-basic -f # Open in separate tab */ -interface CreatePersistedBrowserOutput { - browser_live_view_url: string; +interface CreateBrowserForTestingOutput { + browser_live_view_url?: string; } app.action( - "create-persisted-browser", - async (ctx: KernelContext): Promise => { + "create-browser-for-testing", + async (ctx: KernelContext): Promise => { const kernelBrowser = await kernel.browsers.create({ invocation_id: ctx.invocation_id, - persistence: { - id: "persisted-browser", - }, - stealth: true, // Turns on residential proxy & auto-CAPTCHA solver + stealth: true, + timeout_seconds: 3600, // Keep browser alive for 1 hour }); return { From b70c415cb886296714543e815e513d9c025e546b Mon Sep 17 00:00:00 2001 From: Mason Williams Date: Mon, 1 Dec 2025 14:55:02 -0500 Subject: [PATCH 2/2] refactor: update browser cleanup method usage --- templates/python/sample-app/main.py | 2 +- templates/typescript/sample-app/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/python/sample-app/main.py b/templates/python/sample-app/main.py index 63fd2bb..bd329de 100644 --- a/templates/python/sample-app/main.py +++ b/templates/python/sample-app/main.py @@ -62,7 +62,7 @@ async def get_page_title(ctx: kernel.KernelContext, input_data: PageTitleInput) return {"title": title} finally: - await browser.close() + client.browsers.delete_by_id(kernel_browser.session_id) """ diff --git a/templates/typescript/sample-app/index.ts b/templates/typescript/sample-app/index.ts index 8012b48..ea3a94c 100644 --- a/templates/typescript/sample-app/index.ts +++ b/templates/typescript/sample-app/index.ts @@ -70,7 +70,7 @@ app.action( const title = await page.title(); return { title }; } finally { - await browser.close(); + await kernel.browsers.deleteByID(kernelBrowser.session_id); } } ); @@ -90,7 +90,7 @@ app.action( * kernel logs ts-basic -f # Open in separate tab */ interface CreateBrowserForTestingOutput { - browser_live_view_url?: string; + browser_live_view_url: string; } app.action( "create-browser-for-testing",