Skip to content

Feat: Lightpanda extension #2192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b3c5b9b
feat: add lightpanda structure
nrigaudiere May 20, 2025
85198b8
chore: add lightpanda doc links
nrigaudiere Jun 4, 2025
29dbf66
fix: lightpanda extension instructions
nrigaudiere Jun 20, 2025
33ffbcf
feat: add Lightpanda guide and examples
nrigaudiere Jun 20, 2025
d5505b5
feat: lightpanda - add 3rd example
nrigaudiere Jun 23, 2025
f43f8af
feat: add lightpandaTask
nrigaudiere Jun 23, 2025
11efe5c
fix: lightpanda 3rd example
nrigaudiere Jun 23, 2025
806aeff
fix: lightpanda 1st example
nrigaudiere Jun 23, 2025
76d936c
chore: add changeset
nrigaudiere Jun 24, 2025
72225e7
add v4 tag to guide
nicktrn Jun 24, 2025
fcc50a6
fix: merge lightpanda docker instructions
nrigaudiere Jun 25, 2025
60f3357
fix: add failsafes
nrigaudiere Jun 25, 2025
281de09
add scrape warning
nicktrn Jun 26, 2025
5aec497
lint
nicktrn Jun 26, 2025
2568391
Merge remote-tracking branch 'origin/main' into pr/2192
nicktrn Jun 27, 2025
32e4175
successful login also switches to that profile
nicktrn Jun 27, 2025
b272e30
Merge remote-tracking branch 'origin/main' into pr/2192
nicktrn Jul 2, 2025
73379ce
Merge remote-tracking branch 'origin/main' into pr/2192
nicktrn Jul 3, 2025
c9511b1
update docs and links as this is v4 only
nicktrn Jul 3, 2025
7011482
extension tweaks
nicktrn Jul 3, 2025
636d71b
Merge remote-tracking branch 'origin/main' into pr/2192
nicktrn Jul 28, 2025
54585cb
simplify extension
nicktrn Jul 28, 2025
067f38a
update examples
nicktrn Jul 28, 2025
3464e5e
update docs
nicktrn Jul 28, 2025
c7cb791
Merge remote-tracking branch 'origin/main' into pr/2192
nicktrn Jul 28, 2025
b11d9b7
remove from extensions list as v4 only
nicktrn Jul 28, 2025
f181664
remove from catalog
nicktrn Jul 28, 2025
0a0c06a
update changeset
nicktrn Jul 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/empty-dolls-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Switch to profile after successful login
5 changes: 5 additions & 0 deletions .changeset/rare-mails-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/build": patch
---

Add Lightpanda extension
60 changes: 60 additions & 0 deletions docs/config/extensions/lightpanda.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: "Lightpanda"
sidebarTitle: "lightpanda"
description: "Use the lightpanda build extension to add Lightpanda browser to your project"
tag: "v4"
---

import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";

<UpgradeToV4Note />

To use the Lightpanda browser in your project, add the extension to your `trigger.config.ts` file:

```ts trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk";
import { lightpanda } from "@trigger.dev/build/extensions/lightpanda";

export default defineConfig({
project: "<project ref>",
build: {
extensions: [lightpanda()],
},
});
```

## Options

- `version`: The version of the browser to install. Default: `"latest"`.
- `disableTelemetry`: Whether to disable telemetry. Default: `false`.

For example:

```ts trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk";
import { lightpanda } from "@trigger.dev/build/extensions/lightpanda";

export default defineConfig({
project: "<project ref>",
build: {
extensions: [
lightpanda({
version: "nightly",
disableTelemetry: true,
}),
],
},
});
```

## Development

When running in dev, you will first have to download the Lightpanda browser binary and make sure it's in your `PATH`. See [Lightpanda's installation guide](https://lightpanda.io/docs/getting-started/installation).

## Next steps

<CardGroup>
<Card title="Lightpanda" color="#6ac6e2" icon="bolt" href="/guides/examples/lightpanda">
Learn how to use Lightpanda in your project.
</Card>
</CardGroup>
1 change: 0 additions & 1 deletion docs/config/extensions/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Trigger.dev provides a set of built-in extensions that you can use to customize
| :-------------------------------------------------------------------- | :----------------------------------------------------------------------------- |
| [prismaExtension](/config/extensions/prismaExtension) | Using prisma in your Trigger.dev tasks |
| [pythonExtension](/config/extensions/pythonExtension) | Execute Python scripts in your project |
| [playwright](/config/extensions/playwright) | Use Playwright in your Trigger.dev tasks |
| [puppeteer](/config/extensions/puppeteer) | Use Puppeteer in your Trigger.dev tasks |
| [ffmpeg](/config/extensions/ffmpeg) | Use FFmpeg in your Trigger.dev tasks |
| [aptGet](/config/extensions/aptGet) | Install system packages in your build image |
Expand Down
2 changes: 2 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"config/extensions/pythonExtension",
"config/extensions/playwright",
"config/extensions/puppeteer",
"config/extensions/lightpanda",
"config/extensions/ffmpeg",
"config/extensions/aptGet",
"config/extensions/additionalFiles",
Expand Down Expand Up @@ -362,6 +363,7 @@
"guides/examples/fal-ai-realtime",
"guides/examples/ffmpeg-video-processing",
"guides/examples/firecrawl-url-crawl",
"guides/examples/lightpanda",
"guides/examples/libreoffice-pdf-conversion",
"guides/examples/open-ai-with-retrying",
"guides/examples/pdf-to-image",
Expand Down
227 changes: 227 additions & 0 deletions docs/guides/examples/lightpanda.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
---
title: "Lightpanda"
sidebarTitle: "Lightpanda"
description: "These examples demonstrate how to use Lightpanda with Trigger.dev."
tag: "v4"
---

import ScrapingWarning from "/snippets/web-scraping-warning.mdx";
import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";

<UpgradeToV4Note />

## Overview

Lightpanda is a purpose-built browser for AI and automation workflows. It is 10x faster, uses 10x less RAM than Chrome headless.

Here are a few examples of how to use Lightpanda with Trigger.dev.

<ScrapingWarning />

## Limitations

- Lightpanda does not support the `puppeteer` screenshot feature.

## Using Lightpanda Cloud

### Prerequisites

- A [Lightpanda](https://lightpanda.io/) cloud token

### Get links from a website
In this task we use Lightpanda browser to get links from a provided URL. You will have to pass the URL as a payload when triggering the task.

Make sure to add `LIGHTPANDA_TOKEN` to your Trigger.dev dashboard on the Environment Variables page:
```bash
LIGHTPANDA_TOKEN="<your-token>"
```

```ts trigger/lightpanda-cloud-puppeteer.ts
import { logger, task } from "@trigger.dev/sdk";
import puppeteer from "puppeteer-core";

export const lightpandaCloudPuppeteer = task({
id: "lightpanda-cloud-puppeteer",
machine: {
preset: "micro",
},
run: async (payload: { url: string }, { ctx }) => {
logger.log("Lets get a page's links with Lightpanda!", { payload, ctx });

if (!payload.url) {
logger.warn("Please define the payload url");
throw new Error("payload.url is undefined");
}

const token = process.env.LIGHTPANDA_TOKEN;
if (!token) {
logger.warn("Please define the env variable LIGHTPANDA_TOKEN");
throw new Error("LIGHTPANDA_TOKEN is undefined");
}

// Connect to Lightpanda's cloud
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://cloud.lightpanda.io/ws?browser=lightpanda&token=${token}`,
});
const context = await browser.createBrowserContext();
const page = await context.newPage();

// Dump all the links from the page.
await page.goto(payload.url);

const links = await page.evaluate(() => {
return Array.from(document.querySelectorAll("a")).map((row) => {
return row.getAttribute("href");
});
});

logger.info("Processing done, shutting down…");

await page.close();
await context.close();
await browser.disconnect();

logger.info("✅ Completed");

return {
links,
};
},
});
```

### Proxies

Proxies can be used with your browser via the proxy query string parameter. By default, the proxy used is "datacenter" which is a pool of shared datacenter IPs.
`datacenter` accepts an optional `country` query string parameter which is an [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code.

```bash
# This example will use a German IP
wss://cloud.lightpanda.io/ws?proxy=datacenter&country=de&token=${token}
```

### Session

A session is alive until you close it or the connection is closed. The max duration of a session is 15 minutes.

## Using Lightpanda browser directly

### Prerequisites

- Setup the [Lightpanda build extension](/config/extensions/lightpanda)

### Get the HTML of a webpage

This task will dump the HTML of a provided URL using the Lightpanda browser binary. You will have to pass the URL as a payload when triggering the task.

```ts trigger/lightpanda-fetch.ts
import { logger, task } from "@trigger.dev/sdk";
import { execSync } from "node:child_process";

export const lightpandaFetch = task({
id: "lightpanda-fetch",
machine: {
preset: "micro",
},
run: async (payload: { url: string }, { ctx }) => {
logger.log("Lets get a page's content with Lightpanda!", { payload, ctx });

if (!payload.url) {
logger.warn("Please define the payload url");
throw new Error("payload.url is undefined");
}

const buffer = execSync(`lightpanda fetch --dump ${payload.url}`);

logger.info("✅ Completed");

return {
message: buffer.toString(),
};
},
});
```

### Lightpanda CDP with Puppeteer

This task initializes a Lightpanda CDP server and uses it with `puppeteer-core` to scrape a provided URL.

```ts trigger/lightpanda-cdp.ts
import { logger, task } from "@trigger.dev/sdk";
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
import puppeteer from "puppeteer-core";

const spawnLightpanda = async (host: string, port: string) =>
new Promise<ChildProcessWithoutNullStreams>((resolve, reject) => {
const child = spawn("lightpanda", [
"serve",
"--host",
host,
"--port",
port,
"--log_level",
"info",
]);

child.on("spawn", async () => {
logger.info("Running Lightpanda's CDP server…", {
pid: child.pid,
});

await new Promise((resolve) => setTimeout(resolve, 250));
resolve(child);
});
child.on("error", (e) => reject(e));
});

export const lightpandaCDP = task({
id: "lightpanda-cdp",
machine: {
preset: "micro",
},
run: async (payload: { url: string }, { ctx }) => {
logger.log("Lets get a page's links with Lightpanda!", { payload, ctx });

if (!payload.url) {
logger.warn("Please define the payload url");
throw new Error("payload.url is undefined");
}

const host = process.env.LIGHTPANDA_CDP_HOST ?? "127.0.0.1";
const port = process.env.LIGHTPANDA_CDP_PORT ?? "9222";

// Launch Lightpanda's CDP server
const lpProcess = await spawnLightpanda(host, port);

const browser = await puppeteer.connect({
browserWSEndpoint: `ws://${host}:${port}`,
});
const context = await browser.createBrowserContext();
const page = await context.newPage();

// Dump all the links from the page.
await page.goto(payload.url);

const links = await page.evaluate(() => {
return Array.from(document.querySelectorAll("a")).map((row) => {
return row.getAttribute("href");
});
});

logger.info("Processing done");
logger.info("Shutting down…");

// Close Puppeteer instance
await browser.close();

// Stop Lightpanda's CDP Server
lpProcess.kill();

logger.info("✅ Completed");

return {
links,
};
},
});
```
1 change: 1 addition & 0 deletions docs/guides/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Task code you can copy and paste to use in your project. They can all be extende
| [FFmpeg video processing](/guides/examples/ffmpeg-video-processing) | Use FFmpeg to process a video in various ways and save it to Cloudflare R2. |
| [Firecrawl URL crawl](/guides/examples/firecrawl-url-crawl) | Learn how to use Firecrawl to crawl a URL and return LLM-ready markdown. |
| [LibreOffice PDF conversion](/guides/examples/libreoffice-pdf-conversion) | Convert a document to PDF using LibreOffice. |
| [Lightpanda](/guides/examples/lightpanda) | Use Lightpanda browser (or cloud version) to get a webpage's content. |
| [OpenAI with retrying](/guides/examples/open-ai-with-retrying) | Create a reusable OpenAI task with custom retry options. |
| [PDF to image](/guides/examples/pdf-to-image) | Use `MuPDF` to turn a PDF into images and save them to Cloudflare R2. |
| [Puppeteer](/guides/examples/puppeteer) | Use Puppeteer to generate a PDF or scrape a webpage. |
Expand Down
Binary file added docs/images/intro-lightpanda.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 14 additions & 13 deletions docs/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,24 @@ We provide everything you need to build and manage background tasks: a CLI and S
<Card title="Supabase" img="/images/intro-supabase.jpg" href="/guides/examples/supabase-database-operations"/>
<Card title="DALL•E" img="/images/intro-openai.jpg" href="/guides/examples/dall-e3-generate-image"/>
<Card title="Firecrawl" img="/images/intro-firecrawl.jpg" href="/guides/examples/firecrawl-url-crawl"/>
<Card title="Lightpanda" img="/images/intro-lightpanda.jpg" href="/guides/examples/lightpanda"/>
</CardGroup>

## Explore by build extension

| Extension | What it does | Docs |
|:----------|:------------|:--------------|
| prismaExtension | Use Prisma with Trigger.dev | [Learn more](/config/extensions/prismaExtension) |
| pythonExtension | Execute Python scripts in Trigger.dev | [Learn more](/config/extensions/pythonExtension) |
| puppeteer | Use Puppeteer with Trigger.dev | [Learn more](/config/extensions/puppeteer) |
| ffmpeg | Use FFmpeg with Trigger.dev | [Learn more](/config/extensions/ffmpeg) |
| aptGet | Install system packages with aptGet | [Learn more](/config/extensions/aptGet) |
| additionalFiles | Copy additional files to the build directory | [Learn more](/config/extensions/additionalFiles) |
| additionalPackages | Include additional packages in the build | [Learn more](/config/extensions/additionalPackages) |
| syncEnvVars | Automatically sync environment variables to Trigger.dev | [Learn more](/config/extensions/syncEnvVars) |
| esbuildPlugin | Add existing or custom esbuild plugins to your build process | [Learn more](/config/extensions/esbuildPlugin) |
| emitDecoratorMetadata | Support for the emitDecoratorMetadata TypeScript compiler | [Learn more](/config/extensions/emitDecoratorMetadata) |
| audioWaveform | Support for Audio Waveform in your project | [Learn more](/config/extensions/audioWaveform) |
| Extension | What it does | Docs |
| :-------------------- | :----------------------------------------------------------- | :----------------------------------------------------- |
| prismaExtension | Use Prisma with Trigger.dev | [Learn more](/config/extensions/prismaExtension) |
| pythonExtension | Execute Python scripts in Trigger.dev | [Learn more](/config/extensions/pythonExtension) |
| puppeteer | Use Puppeteer with Trigger.dev | [Learn more](/config/extensions/puppeteer) |
| ffmpeg | Use FFmpeg with Trigger.dev | [Learn more](/config/extensions/ffmpeg) |
| aptGet | Install system packages with aptGet | [Learn more](/config/extensions/aptGet) |
| additionalFiles | Copy additional files to the build directory | [Learn more](/config/extensions/additionalFiles) |
| additionalPackages | Include additional packages in the build | [Learn more](/config/extensions/additionalPackages) |
| syncEnvVars | Automatically sync environment variables to Trigger.dev | [Learn more](/config/extensions/syncEnvVars) |
| esbuildPlugin | Add existing or custom esbuild plugins to your build process | [Learn more](/config/extensions/esbuildPlugin) |
| emitDecoratorMetadata | Support for the emitDecoratorMetadata TypeScript compiler | [Learn more](/config/extensions/emitDecoratorMetadata) |
| audioWaveform | Support for Audio Waveform in your project | [Learn more](/config/extensions/audioWaveform) |

## Getting help

Expand Down
Loading
Loading