Skip to content

Commit e0de1c7

Browse files
authored
Merge pull request #11 from browserbase/proxy
Proxies - true
2 parents ef26fed + 08df97b commit e0de1c7

File tree

3 files changed

+50
-44
lines changed

3 files changed

+50
-44
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,6 @@ target/
8181
.env.local
8282

8383
# pnpm
84-
pnpm-lock.yaml
84+
pnpm-lock.yaml
85+
86+
test/

app/api/cua/agent/browserbase.ts

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export class BrowserbaseBrowser extends BasePlaywrightComputer {
3838
private projectId: string;
3939
private session: BrowserbaseSession | null = null;
4040
private region: string;
41-
private proxy: boolean;
41+
private proxies: boolean;
4242
private sessionId: string | null;
4343

4444
constructor(
4545
width: number = 1024,
4646
height: number = 768,
47-
region: string = "us-west-2",
48-
proxy: boolean = false,
47+
region: string = "us-east-1",
48+
proxies: boolean = true,
4949
sessionId: string | null = null
5050
) {
5151
/**
@@ -54,18 +54,18 @@ export class BrowserbaseBrowser extends BasePlaywrightComputer {
5454
* @param width - The width of the browser viewport. Default is 1024.
5555
* @param height - The height of the browser viewport. Default is 768.
5656
* @param region - The region for the Browserbase session. Default is "us-west-2". Pick a region close to you for better performance. https://docs.browserbase.com/guides/multi-region
57-
* @param proxy - Whether to use a proxy for the session. Default is False. Turn on proxies if you're browsing is frequently interrupted. https://docs.browserbase.com/features/proxies
57+
* @param proxies - Whether to use a proxy for the session. Default is False. Turn on proxies if you're browsing is frequently interrupted. https://docs.browserbase.com/features/proxies
5858
* @param sessionId - Optional. If provided, use an existing session instead of creating a new one.
5959
*/
6060
super();
6161
// We're using a dynamic import here as a workaround since we don't have the actual types
6262
// In a real project, you would install the proper types and import correctly
63-
this.bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY });
63+
this.bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY});
6464
this.projectId = process.env.BROWSERBASE_PROJECT_ID!;
6565
this.session = null;
6666
this.dimensions = [width, height];
6767
this.region = region;
68-
this.proxy = proxy;
68+
this.proxies = proxies;
6969
this.sessionId = sessionId;
7070
}
7171

@@ -105,7 +105,7 @@ export class BrowserbaseBrowser extends BasePlaywrightComputer {
105105
| "us-east-1"
106106
| "eu-central-1"
107107
| "ap-southeast-1",
108-
proxies: this.proxy,
108+
proxies: true,
109109
keepAlive: true,
110110
};
111111

@@ -126,40 +126,43 @@ export class BrowserbaseBrowser extends BasePlaywrightComputer {
126126
// Inject inline cursor-rendering script globally for every page
127127
const pages = context.pages();
128128
const page = pages[pages.length - 1];
129-
page.evaluate(() => {
130-
const CURSOR_ID = '__cursor__';
129+
page
130+
.evaluate(() => {
131+
const CURSOR_ID = "__cursor__";
131132

132-
// Check if cursor element already exists
133-
if (document.getElementById(CURSOR_ID)) return;
133+
// Check if cursor element already exists
134+
if (document.getElementById(CURSOR_ID)) return;
134135

135-
const cursor = document.createElement('div');
136-
cursor.id = CURSOR_ID;
137-
Object.assign(cursor.style, {
138-
position: 'fixed',
139-
top: '0px',
140-
left: '0px',
141-
width: '20px',
142-
height: '20px',
143-
backgroundImage: 'url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 24 24\' fill=\'black\' stroke=\'white\' stroke-width=\'1\' stroke-linejoin=\'round\' stroke-linecap=\'round\'><polygon points=\'2,2 2,22 8,16 14,22 17,19 11,13 20,13\'/></svg>")',
144-
backgroundSize: 'cover',
145-
pointerEvents: 'none',
146-
zIndex: '99999',
147-
transform: 'translate(-2px, -2px)',
148-
});
149-
150-
document.body.appendChild(cursor);
136+
const cursor = document.createElement("div");
137+
cursor.id = CURSOR_ID;
138+
Object.assign(cursor.style, {
139+
position: "fixed",
140+
top: "0px",
141+
left: "0px",
142+
width: "20px",
143+
height: "20px",
144+
backgroundImage:
145+
"url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black' stroke='white' stroke-width='1' stroke-linejoin='round' stroke-linecap='round'><polygon points='2,2 2,22 8,16 14,22 17,19 11,13 20,13'/></svg>\")",
146+
backgroundSize: "cover",
147+
pointerEvents: "none",
148+
zIndex: "99999",
149+
transform: "translate(-2px, -2px)",
150+
});
151151

152-
document.addEventListener("mousemove", (e) => {
153-
cursor.style.top = `${e.clientY}px`;
154-
cursor.style.left = `${e.clientX}px`;
155-
});
156-
document.addEventListener("mousedown", (e) => {
157-
cursor.style.top = `${e.clientY}px`;
158-
cursor.style.left = `${e.clientX}px`;
152+
document.body.appendChild(cursor);
153+
154+
document.addEventListener("mousemove", (e) => {
155+
cursor.style.top = `${e.clientY}px`;
156+
cursor.style.left = `${e.clientX}px`;
157+
});
158+
document.addEventListener("mousedown", (e) => {
159+
cursor.style.top = `${e.clientY}px`;
160+
cursor.style.left = `${e.clientX}px`;
161+
});
162+
})
163+
.catch((error) => {
164+
console.error("Error injecting cursor-rendering script:", error);
159165
});
160-
}).catch((error) => {
161-
console.error("Error injecting cursor-rendering script:", error);
162-
});
163166

164167
// Only navigate to Google if it's a new session
165168
if (!this.sessionId) {

app/api/session/route.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ async function createSession(timezone?: string) {
9797
browserSettings,
9898
keepAlive: true,
9999
region: getClosestRegion(timezone),
100+
proxies: true,
100101
timeout: 600,
101102
});
102103
return {
103-
session
104+
session,
104105
};
105106
}
106107

@@ -126,19 +127,19 @@ export async function POST(request: Request) {
126127
try {
127128
const body = await request.json();
128129
const timezone = body.timezone as string;
129-
const { session } = await createSession(
130-
timezone
131-
);
130+
const { session } = await createSession(timezone);
132131
const browser = await chromium.connectOverCDP(session.connectUrl);
133132
const defaultContext = browser.contexts()[0];
134133
const page = defaultContext.pages()[0];
135-
await page.goto("https://www.google.com", { waitUntil: "domcontentloaded" });
134+
await page.goto("https://www.google.com", {
135+
waitUntil: "domcontentloaded",
136+
});
136137
const liveUrl = await getDebugUrl(session.id);
137138
return NextResponse.json({
138139
success: true,
139140
sessionId: session.id,
140141
sessionUrl: liveUrl,
141-
connectUrl: session.connectUrl
142+
connectUrl: session.connectUrl,
142143
});
143144
} catch (error) {
144145
console.error("Error creating session:", error);

0 commit comments

Comments
 (0)