Skip to content

feat: add browser provider to connect to a remote chrome instance - #82

Open
pasdam wants to merge 1 commit into
hyperbrowserai:mainfrom
pasdam:main
Open

feat: add browser provider to connect to a remote chrome instance#82
pasdam wants to merge 1 commit into
hyperbrowserai:mainfrom
pasdam:main

Conversation

@pasdam

Copy link
Copy Markdown

This adds a new browser provider to allow the user to connect to a remote chrome instance. Helpful in cases where you want to connect for instance to a playwright instance running in docker.

Example

Compose file:

services:
# The Browser Instanceplaywright-server:
image: mcr.microsoft.com/playwright:v1.57.0-noblecommand: /bin/sh -c "npx -y playwright@1.57.0 run-server --port 3000 --host 0.0.0.0"environment:
- DEBUG=pw:api,pw:browser*ports:
- "3000:3000"shm_size: "2gb"hyper-agent-runner:
build: .environment:
- BROWSER_WS_ENDPOINT=ws://playwright-server:3000
- OPENAI_API_KEY=${OPENAI_API_KEY}volumes:
- ./index.ts:/app/index.tsdepends_on:
- playwright-server

Typescript client:

import{chromium,Browser,Page}from"playwright-core";import{HyperAgent}from"@hyperbrowser/agent";asyncfunctionrunRemoteAgent(){constwsEndpoint=process.env.BROWSER_WS_ENDPOINT;console.log("--- Initializing HyperAgent Connection ---");// 2. Initialize HyperAgentconstagent=newHyperAgent({llm: {provider: "openai",model: "gpt-5-mini"},browserProvider: "RemoteChrome",remoteChromeConfig: {wsEndpoint: wsEndpoint!,},debug: true,});console.log("Starting AI Task...");try{constresult=awaitagent.executeTask("Go to news.ycombinator.com and give me the top story.");console.log("✅ Task Completed Successfully!");console.log(result.output);}catch(error: any){// 4. Catch and Log Errorsconsole.error("❌ Agent Execution Failed!");// Detailed error loggingif(error.message.includes("ECONNREFUSED")){console.error("DEBUG: Could not reach the Docker container. Is it running on the correct port?");}elseif(error.message.includes("401")||error.message.includes("API key")){console.error("DEBUG: Authentication error. Check your HYPERBROWSER_API_KEY or OPENAI_API_KEY");}else{console.error("STACK TRACE:",error);}}finally{console.log("--- Cleaning Up Resources ---");awaitagent.closeAgent();console.log("Session ended.");}}runRemoteAgent()

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@pasdam