Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion templates/python/advanced-sample/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions templates/python/sample-app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,30 @@ 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:
A dictionary containing the browser live view url
Invoke this via CLI:
kernel login # or: export KERNEL_API_KEY=<your_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,
}
}
3 changes: 0 additions & 3 deletions templates/typescript/advanced-sample/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ app.action("test-captcha-solver", async (ctx: KernelContext): Promise<void> => {
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);

Expand Down
20 changes: 9 additions & 11 deletions templates/typescript/sample-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,29 @@ app.action<PageTitleInput, PageTitleOutput>(
);

/**
* 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:
* A dictionary containing the browser live view url
* Invoke this via CLI:
* kernel login # or: export KERNEL_API_KEY=<your_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<CreatePersistedBrowserOutput> => {
"create-browser-for-testing",
async (ctx: KernelContext): Promise<CreateBrowserForTestingOutput> => {
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 {
Expand Down
Loading