From 3c0fa3da5592f470ef49249a964bebd99a2a13f9 Mon Sep 17 00:00:00 2001 From: Anirudh Kamath Date: Mon, 5 May 2025 17:53:39 -0700 Subject: [PATCH 1/3] initial spike on patchright --- lib/StagehandContext.ts | 2 +- lib/StagehandPage.ts | 4 ++-- lib/handlers/actHandler.ts | 2 +- lib/handlers/handlerUtils/actHandlerUtils.ts | 2 +- lib/index.ts | 2 +- package.json | 3 ++- pnpm-lock.yaml | 21 ++++++++++++++++++++ types/act.ts | 2 +- types/context.ts | 2 +- types/page.ts | 2 +- types/stagehand.ts | 2 +- 11 files changed, 33 insertions(+), 11 deletions(-) diff --git a/lib/StagehandContext.ts b/lib/StagehandContext.ts index 5d8bf4e66..063f194cf 100644 --- a/lib/StagehandContext.ts +++ b/lib/StagehandContext.ts @@ -1,7 +1,7 @@ import type { BrowserContext as PlaywrightContext, Page as PlaywrightPage, -} from "@playwright/test"; +} from "patchright"; import { Stagehand } from "./index"; import { StagehandPage } from "./StagehandPage"; import { Page } from "../types/page"; diff --git a/lib/StagehandPage.ts b/lib/StagehandPage.ts index aab2ace68..6113c9065 100644 --- a/lib/StagehandPage.ts +++ b/lib/StagehandPage.ts @@ -1,6 +1,6 @@ import { Browserbase } from "@browserbasehq/sdk"; -import type { CDPSession, Page as PlaywrightPage } from "@playwright/test"; -import { chromium } from "@playwright/test"; +import type { CDPSession, Page as PlaywrightPage } from "patchright"; +import { chromium } from "patchright"; import { z } from "zod"; import { Page, defaultExtractSchema } from "../types/page"; import { diff --git a/lib/handlers/actHandler.ts b/lib/handlers/actHandler.ts index d3442f07e..ef7c6547c 100644 --- a/lib/handlers/actHandler.ts +++ b/lib/handlers/actHandler.ts @@ -1,4 +1,4 @@ -import { Locator } from "@playwright/test"; +import { Locator } from "patchright"; import { LogLine } from "../../types/log"; import { PlaywrightCommandException, diff --git a/lib/handlers/handlerUtils/actHandlerUtils.ts b/lib/handlers/handlerUtils/actHandlerUtils.ts index 339a97df3..1e16c0da6 100644 --- a/lib/handlers/handlerUtils/actHandlerUtils.ts +++ b/lib/handlers/handlerUtils/actHandlerUtils.ts @@ -1,4 +1,4 @@ -import { Page, Locator } from "@playwright/test"; +import { Page, Locator } from "patchright"; import { PlaywrightCommandException } from "../../../types/playwright"; import { StagehandPage } from "../../StagehandPage"; import { getNodeFromXpath } from "@/lib/dom/utils"; diff --git a/lib/index.ts b/lib/index.ts index 45b81e0b9..c628b73f6 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,5 +1,5 @@ import { Browserbase } from "@browserbasehq/sdk"; -import { Browser, chromium } from "@playwright/test"; +import { Browser, chromium } from "patchright"; import dotenv from "dotenv"; import fs from "fs"; import os from "os"; diff --git a/package.json b/package.json index b294906a1..803778409 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "module": "./dist/index.js", "types": "./dist/index.d.ts", "scripts": { - "example": "pnpm --filter @browserbasehq/stagehand-examples run start", + "example": "pnpm --filter @browserbasehq/stagehand-examples run start", "format": "prettier --write .", "prettier": "prettier --check .", "prettier:fix": "prettier --write .", @@ -72,6 +72,7 @@ "@google/genai": "^0.8.0", "ai": "^4.3.9", "openai": "^4.87.1", + "patchright": "^1.52.1", "pino": "^9.6.0", "pino-pretty": "^13.0.0", "playwright": "^1.52.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2a16435b2..cc1da412e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ importers: openai: specifier: ^4.87.1 version: 4.96.2(ws@8.18.1)(zod@3.24.3) + patchright: + specifier: ^1.52.1 + version: 1.52.1 pino: specifier: ^9.6.0 version: 9.6.0 @@ -2503,6 +2506,16 @@ packages: partial-json@0.1.7: resolution: {integrity: sha512-Njv/59hHaokb/hRUjce3Hdv12wd60MtM9Z5Olmn+nehe0QDAsRtRbJPvJ0Z91TusF0SuZRIvnM+S4l6EIP8leA==} + patchright-core@1.52.0: + resolution: {integrity: sha512-8a3vSEZ8gbmEfwmidRQbn+sCpBswQ//ZGXuD5cHgJEc+/ImGebqOgqNPOzL1qX923ku/A50PGloLwrAWwkxK1g==} + engines: {node: '>=18'} + hasBin: true + + patchright@1.52.1: + resolution: {integrity: sha512-75wiV0s6tOmMtvhCQ/Lgp3dS/8xCKfx81r62D37HRmxwaPMhKxRv9orOOQQx1SgK6xZYW4zG10/ob4ak62cT8Q==} + engines: {node: '>=18'} + hasBin: true + path-exists@4.0.0: resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==} engines: {node: '>=8'} @@ -5526,6 +5539,14 @@ snapshots: partial-json@0.1.7: optional: true + patchright-core@1.52.0: {} + + patchright@1.52.1: + dependencies: + patchright-core: 1.52.0 + optionalDependencies: + fsevents: 2.3.2 + path-exists@4.0.0: {} path-key@3.1.1: {} diff --git a/types/act.ts b/types/act.ts index bdccf4299..f9f9c4aff 100644 --- a/types/act.ts +++ b/types/act.ts @@ -1,5 +1,5 @@ import { LLMClient } from "../lib/llm/LLMClient"; -import { Locator } from "@playwright/test"; +import { Locator } from "patchright"; import { Logger } from "@/types/log"; import { StagehandPage } from "@/lib/StagehandPage"; diff --git a/types/context.ts b/types/context.ts index 2c8976554..3479846a8 100644 --- a/types/context.ts +++ b/types/context.ts @@ -1,4 +1,4 @@ -import type { BrowserContext as PlaywrightContext } from "@playwright/test"; +import type { BrowserContext as PlaywrightContext } from "patchright"; import { Page } from "../types/page"; export interface AXNode { diff --git a/types/page.ts b/types/page.ts index 3d5706012..261a1e67a 100644 --- a/types/page.ts +++ b/types/page.ts @@ -2,7 +2,7 @@ import type { Browser as PlaywrightBrowser, BrowserContext as PlaywrightContext, Page as PlaywrightPage, -} from "@playwright/test"; +} from "patchright"; import { z } from "zod"; import type { ActOptions, diff --git a/types/stagehand.ts b/types/stagehand.ts index 25bae03a8..effa7f156 100644 --- a/types/stagehand.ts +++ b/types/stagehand.ts @@ -4,7 +4,7 @@ import { LLMProvider } from "../lib/llm/LLMProvider"; import { LogLine } from "./log"; import { AvailableModel, ClientOptions } from "./model"; import { LLMClient } from "../lib/llm/LLMClient"; -import { Cookie } from "@playwright/test"; +import { Cookie } from "patchright"; import { AgentProviderType } from "./agent"; export interface ConstructorParams { From 0ae5800bf74cf91b4a2b1c54fc3a9f0505f48ef9 Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Tue, 6 May 2025 13:47:40 -0700 Subject: [PATCH 2/3] import from patchright --- lib/a11y/utils.ts | 2 +- lib/handlers/agentHandler.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/a11y/utils.ts b/lib/a11y/utils.ts index e82b975d8..489015648 100644 --- a/lib/a11y/utils.ts +++ b/lib/a11y/utils.ts @@ -1,7 +1,7 @@ import { AccessibilityNode, TreeResult, AXNode } from "../../types/context"; import { StagehandPage } from "../StagehandPage"; import { LogLine } from "../../types/log"; -import { CDPSession, Page, Locator } from "playwright"; +import { CDPSession, Page, Locator } from "patchright"; import { PlaywrightCommandMethodNotSupportedException, PlaywrightCommandException, diff --git a/lib/handlers/agentHandler.ts b/lib/handlers/agentHandler.ts index 5e6a3325f..378a9b8f0 100644 --- a/lib/handlers/agentHandler.ts +++ b/lib/handlers/agentHandler.ts @@ -3,7 +3,7 @@ import { AgentProvider } from "../agent/AgentProvider"; import { StagehandAgent } from "../agent/StagehandAgent"; import { AgentClient } from "../agent/AgentClient"; import { LogLine } from "../../types/log"; -import { Page } from "playwright"; +import { Page } from "patchright"; import { AgentExecuteOptions, AgentAction, From a5dc17cbee87c1f57771970a45e0ed00519bcd22 Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Tue, 6 May 2025 15:28:53 -0700 Subject: [PATCH 3/3] ignore deterministic evals dir --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index d97b9cb50..8996e459a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,5 +16,5 @@ "skipLibCheck": true, "declaration": true }, - "exclude": ["node_modules", "dist", ".eslintrc.cjs"] + "exclude": ["node_modules", "dist", ".eslintrc.cjs", "evals/deterministic/"] }