Skip to content

Commit c591fc6

Browse files
authored
Use playwright core on serverless env (#11)
1 parent c1a6e28 commit c591fc6

File tree

6 files changed

+32
-44
lines changed

6 files changed

+32
-44
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Used playwright-core in serverless environments
12+
1013
## [0.1.0] - 2025-06-13
1114

1215
### Added

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,28 @@ npm install @lightfeed/browser-agent
2828

2929
Perfect for AWS Lambda and other serverless environments. Uses [@sparticuz/chromium](https://github.com/Sparticuz/chromium) to run Chrome in serverless environments with minimal cold start times and memory usage.
3030

31+
> [!IMPORTANT]
32+
> This project uses Playwright, which ships with a specific version of Chromium. You need to install the matching version of `@sparticuz/chromium`. For example, we are using [Playwright 1.48](https://playwright.dev/docs/release-notes#version-148) (which supports Chromium 130), you should install `@sparticuz/chromium@130`.
33+
3134
```typescript
32-
import { BrowserAgent } from '@lightfeed/browser-agent';
33-
import chromium from '@sparticuz/chromium';
34-
import { AxiosProxyConfig } from 'axios';
35+
import { BrowserAgent } from "@lightfeed/browser-agent";
36+
import chromium from "@sparticuz/chromium";
37+
import { AxiosProxyConfig } from "axios";
3538

3639
const agent = new BrowserAgent({
37-
browserProvider: 'Serverless',
40+
browserProvider: "Serverless",
3841
serverlessConfig: {
3942
executablePath: await chromium.executablePath(),
4043
options: {
4144
args: chromium.args,
4245
},
4346
// Use proxy (optional)
4447
proxy: {
45-
host: 'proxy.example.com',
48+
host: "proxy.example.com",
4649
port: 8080,
4750
auth: {
48-
username: 'user',
49-
password: 'pass'
51+
username: "user",
52+
password: "pass"
5053
}
5154
} as AxiosProxyConfig
5255
}
@@ -55,9 +58,9 @@ const agent = new BrowserAgent({
5558
// Example Lambda handler
5659
export const handler = async (event) => {
5760
const page = await agent.newPage();
58-
await page.goto('https://ycombinator.com/companies');
61+
await page.goto("https://ycombinator.com/companies");
5962

60-
page.ai('Find real estate YC startups in the latest two batches');
63+
page.ai("Find real estate YC startups in the latest two batches");
6164
// ...
6265
};
6366
```
@@ -70,19 +73,19 @@ Connect to any remote browser instance via WebSocket. Great for:
7073
- Browser farms and proxy services
7174

7275
```typescript
73-
import { BrowserAgent } from '@lightfeed/browser-agent';
76+
import { BrowserAgent } from "@lightfeed/browser-agent";
7477

7578
const agent = new BrowserAgent({
76-
browserProvider: 'Remote',
79+
browserProvider: "Remote",
7780
remoteConfig: {
78-
browserWSEndpoint: 'ws://your-remote-browser:9222/devtools/browser/ws'
81+
browserWSEndpoint: "ws://your-remote-browser:9222/devtools/browser/ws"
7982
}
8083
});
8184

8285
const page = await agent.newPage();
83-
await page.goto('https://amazon.com');
86+
await page.goto("https://amazon.com");
8487

85-
page.ai('Search for organic products and go to the second page');
88+
page.ai("Search for organic products and go to the second page");
8689
```
8790

8891
### Local Browser
@@ -93,16 +96,16 @@ Use your local Chrome browser for development and testing. Perfect for:
9396
- Quick prototyping
9497

9598
```typescript
96-
import { BrowserAgent } from '@lightfeed/browser-agent';
99+
import { BrowserAgent } from "@lightfeed/browser-agent";
97100

98101
const agent = new BrowserAgent({
99-
browserProvider: 'Local'
102+
browserProvider: "Local"
100103
});
101104

102105
const page = await agent.newPage();
103-
await page.goto('https://news.ycombinator.com');
106+
await page.goto("https://news.ycombinator.com");
104107

105-
page.ai('Navigate to show section and go to the second post');
108+
page.ai("Navigate to show section and go to the second post");
106109
```
107110

108111
## Contributing

package-lock.json

Lines changed: 5 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"merge-images": "^2.0.0",
5858
"minimatch": "^9.0.3",
5959
"ora": "5.4.1",
60-
"playwright": "npm:rebrowser-playwright@1.49.1",
60+
"playwright": "npm:rebrowser-playwright-core@1.48.2",
6161
"readline": "^1.3.0",
6262
"turndown": "^7.2.0",
6363
"zod": "^3.24.1",

scripts/test-async.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import chalk from "chalk";
55
dotenv.config();
66

77
const agent = new BrowserAgent({
8-
// a: process.env.OPENAI_API_KEY,
8+
maxSteps: 2,
99
});
1010

1111
(async () => {

src/types/browser-providers/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ abstract class BrowserProvider<T> {
44
abstract session: unknown;
55
abstract start(): Promise<Browser>;
66
abstract close(): Promise<void>;
7-
abstract getSession(): T|null;
7+
abstract getSession(): T | null;
88
}
99

1010
export default BrowserProvider;

0 commit comments

Comments
 (0)