Skip to content

Playwright (no MCP)

If you’d rather skip MCP entirely, you can drive a Kifas cloud browser the same way you’d drive Browserless or Playwright Cloud — playwright.connectOverCDP(URL).

  1. Call kifas.session.create (via MCP or REST) to get a connect_url like wss://api.kifas.io/connect?token=....
  2. Pass that URL to chromium.connectOverCDP().
  3. Drive the browser with the standard Playwright API.

The connect_url is single-use; it embeds a short-lived token tied to your session.

import { chromium } from 'playwright'

// Step 1: ask Kifas for a session.
const resp = await fetch('https://mcp.kifas.io/', {
method: 'POST',
headers: {
  'Authorization': `Bearer ${process.env.KIFAS_API_KEY}`,
  'Content-Type': 'application/json',
},
body: JSON.stringify({
  jsonrpc: '2.0',
  id: 1,
  method: 'tools/call',
  params: { name: 'kifas.session.create', arguments: { browser: 'chromium' } },
}),
})
const session = (await resp.json()).result as { connect_url: string; session_id: string }
console.log('session id:', session.session_id)

// Step 2: drive it like any Playwright browser.
const browser = await chromium.connectOverCDP(session.connect_url)
const ctx = await browser.contexts()[0] ?? await browser.newContext()
const page = await ctx.newPage()
await page.goto('https://example.com')
console.log('title:', await page.title())
await browser.close()

Sign in at app.kifas.io to run snippets against a real cloud session.

import os, json, httpx
from playwright.sync_api import sync_playwright
resp = httpx.post(
"https://mcp.kifas.io/",
headers={
"Authorization": f"Bearer {os.environ['KIFAS_API_KEY']}",
"Content-Type": "application/json",
},
json={
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {"name": "kifas.session.create", "arguments": {"browser": "chromium"}},
},
).json()
connect_url = resp["result"]["connect_url"]
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(connect_url)
page = browser.new_page()
page.goto("https://example.com")
print(page.title())
browser.close()

When you export a workflow from Kifas as Playwright code, the generated spec imports @kifas/playwright — helpers for reusing logins and auth primitives captured in Kifas. Install it alongside Playwright:

Terminal window
npm install --save-dev @kifas/playwright @playwright/test
import { test } from '@playwright/test'
import { kifas } from '@kifas/playwright'
test('checkout', async ({ page }) => {
await kifas.state.load(page, 'logged-in-user')
await page.goto('https://example.com/cart')
})

Set KIFAS_API_KEY in the environment. The key needs state:read and state:write to use kifas.state, and workflow:run to use kifas.auth.

A login captured in Kifas is reusable from your own CI and vice versa — both read the same state handles.

  • Choose MCP when an agent is driving the browser (Cursor, Claude Code, custom agents). Tool discovery + structured output + auto-async helps.
  • Choose direct CDP when you have an existing Playwright test suite and just want to swap the local browser for a Kifas cloud browser. Drop-in replacement.

Both paths share quotas, audit, and tier limits — the choice is purely ergonomic.