From a7e5de5e4ff38f8f6f36e81176fa9281467e81a9 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Sat, 10 Jan 2026 23:47:30 -0600 Subject: [PATCH] install --- package.json | 6 ++++-- scripts/postinstall.js | 13 +++++++++++++ src/actions.ts | 2 +- src/browser.ts | 2 +- src/index.ts | 16 ++++++++++++++++ src/types.ts | 2 +- 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 scripts/postinstall.js diff --git a/package.json b/package.json index 6d83286..730c5d6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "format": "prettier --write 'src/**/*.ts'", "format:check": "prettier --check 'src/**/*.ts'", "test": "vitest run", - "test:watch": "vitest" + "test:watch": "vitest", + "postinstall": "node scripts/postinstall.js" }, "keywords": [ "browser", @@ -28,11 +29,12 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "playwright": "^1.40.0", + "playwright-core": "^1.40.0", "zod": "^3.22.4" }, "devDependencies": { "@types/node": "^20.10.0", + "playwright": "^1.40.0", "prettier": "^3.7.4", "tsx": "^4.6.0", "typescript": "^5.3.0", diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 0000000..a47cb04 --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,13 @@ +#!/usr/bin/env node + +const message = ` +╔═══════════════════════════════════════════════════════════════════════════╗ +║ agent-browser was installed successfully! ║ +║ Please run the following command to download browser binaries: ║ +║ ║ +║ npx agent-browser install ║ +║ ║ +╚═══════════════════════════════════════════════════════════════════════════╝ +`; + +console.log(message); diff --git a/src/actions.ts b/src/actions.ts index f34aed1..ffc84b3 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -1,4 +1,4 @@ -import type { Page, Frame } from 'playwright'; +import type { Page, Frame } from 'playwright-core'; import type { BrowserManager } from './browser.js'; import type { Command, diff --git a/src/browser.ts b/src/browser.ts index a9c2f90..d3cf16c 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -10,7 +10,7 @@ import { type Dialog, type Request, type Route, -} from 'playwright'; +} from 'playwright-core'; import type { LaunchCommand } from './types.js'; interface TrackedRequest { diff --git a/src/index.ts b/src/index.ts index 6175dc1..de1fe0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; +import { execSync } from 'child_process'; import { send, setDebug, setSession, getSession } from './client.js'; import type { Response } from './types.js'; @@ -109,6 +110,9 @@ ${c('yellow', 'Debug:')} ${c('cyan', 'console')} View console logs ${c('cyan', 'errors')} View page errors +${c('yellow', 'Setup:')} + ${c('cyan', 'install')} Install browser binaries + ${c('yellow', 'Options:')} --session Isolated session (or AGENT_BROWSER_SESSION env) --json JSON output @@ -946,6 +950,18 @@ async function main(): Promise { process.exit(0); } + case 'install': { + console.log(c('cyan', 'Installing Playwright browsers...')); + try { + execSync('npx playwright install', { stdio: 'inherit' }); + console.log(c('green', '✓'), 'Browsers installed successfully'); + process.exit(0); + } catch (error) { + console.error(c('red', '✗'), 'Failed to install browsers'); + process.exit(1); + } + } + // === Legacy aliases for backwards compatibility === case 'url': cmd = { id, action: 'url' }; diff --git a/src/types.ts b/src/types.ts index 8ef443d..64f1a66 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import type { Page, Browser, BrowserContext } from 'playwright'; +import type { Page, Browser, BrowserContext } from 'playwright-core'; // Base command structure export interface BaseCommand {