Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions browserless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Browserless App

This is a deco app for Browserless API, which provides production-ready APIs for browser automation tasks.

## API Endpoints

Browserless has production-ready APIs that you can use depending on your use-case:

### Browser APIs

The Browser APIs help you execute specific tasks for your use-case:

* `/content` - Returns HTML of dynamic content
* `/download` - Returns files Chrome has downloaded
* `/screenshot` - Captures a .png, .jpg, or .webp of a page
* `/pdf` - Exports a page as a PDF
* `/scrape` - Returns structured JSON data from a page
* `/function` - Runs HTTP requests without installing a library
* `/unblock` - Returns HTML, screenshots or cookies for protected sites
* `/performance` - Runs parallel Google Lighthouse tests

### Management APIs

Enterprise customers can use these APIs to monitor their deployment:

* `/sessions` - Gathers information about currently running sessions
* `/metrics` - Provides information about worker configuration
* `/config` - Retrieves an array of session statistics

## Authentication

To authenticate API calls, you need to provide an API key. This key is passed as a query parameter (`?token=YOUR_API_KEY`) rather than as a bearer token in the Authorization header. You can set the `token` property when using this app, and the client will automatically add it to requests.
13 changes: 13 additions & 0 deletions browserless/actions/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { AppContext } from "../mod.ts";

/**
* @title Get Config
* @description Retrieves configuration information
*/
export default async function config(
_props: Record<string, never>,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.getConfig();
}
14 changes: 14 additions & 0 deletions browserless/actions/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { AppContext } from "../mod.ts";
import { ContentParams } from "../client.ts";

/**
* @title Get Content
* @description Returns the HTML content of a page
*/
export default async function content(
props: ContentParams,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.getContent(props);
}
13 changes: 13 additions & 0 deletions browserless/actions/download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { DownloadParams } from "../client.ts";
import type { AppContext } from "../mod.ts";
/**
* @title Download File
* @description Downloads files using the browser
*/
export default async function download(
props: DownloadParams,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.download(props);
}
14 changes: 14 additions & 0 deletions browserless/actions/function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { AppContext } from "../mod.ts";
import { FunctionParams } from "../client.ts";

/**
* @title Execute Function
* @description Runs JavaScript code in the browser context
*/
export default async function executeFunction<T = unknown>(
props: FunctionParams,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.executeFunction<T>(props);
}
13 changes: 13 additions & 0 deletions browserless/actions/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { AppContext } from "../mod.ts";

/**
* @title Get Metrics
* @description Retrieves metrics information about the worker
*/
export default async function metrics(
_props: Record<string, never>,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.getMetrics();
}
30 changes: 30 additions & 0 deletions browserless/actions/pdf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { AppContext } from "../mod.ts";
import { PdfParams } from "../client.ts";

/**
* @title Generate PDF
* @description Creates a PDF from a page
*
* This action returns a Blob object containing the PDF data.
* You can convert this Blob to:
* 1. A URL: URL.createObjectURL(blob)
* 2. A base64 string: Use FileReader to read as data URL
* 3. Save it as an asset using website/loaders/asset.ts
*
* @example
* ```ts
* import { pdf } from "apps/browserless/actions/pdf.ts";
* import { asset } from "apps/website/loaders/asset.ts";
*
* // Example of saving to an asset
* const blob = await pdf({url: "https://example.com"});
* const savedPdf = await asset({file: blob, name: "document.pdf"});
* ```
*/
export default async function pdf(
props: PdfParams,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.getPdf(props);
}
14 changes: 14 additions & 0 deletions browserless/actions/performance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { AppContext } from "../mod.ts";
import { PerformanceParams } from "../client.ts";

/**
* @title Test Performance
* @description Runs Google Lighthouse tests on a page
*/
export default async function performance(
props: PerformanceParams,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.testPerformance(props);
}
14 changes: 14 additions & 0 deletions browserless/actions/scrape.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { AppContext } from "../mod.ts";
import { ScrapeParams } from "../client.ts";

/**
* @title Scrape Page
* @description Extracts structured data from a page
*/
export default async function scrape<T = Record<string, unknown>>(
props: ScrapeParams,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.scrape<T>(props);
}
14 changes: 14 additions & 0 deletions browserless/actions/screenshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ScreenshotParams } from "../client.ts";
import type { AppContext } from "../mod.ts";

/**
* @title Take Screenshot
* @description Captures a screenshot of a page
*/
export default async function screenshot(
props: ScreenshotParams,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.getScreenshot(props);
}
13 changes: 13 additions & 0 deletions browserless/actions/sessions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { AppContext } from "../mod.ts";

/**
* @title Get Sessions
* @description Retrieves information about currently running sessions
*/
export default async function sessions(
_props: Record<string, never>,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.getSessions();
}
14 changes: 14 additions & 0 deletions browserless/actions/unblock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { UnblockParams } from "../client.ts";
import type { AppContext } from "../mod.ts";

/**
* @title Unblock Page
* @description Bypasses protection on websites and returns content, screenshots, or cookies
*/
export default async function unblock(
props: UnblockParams,
_req: Request,
ctx: AppContext,
): Promise<unknown> {
return await ctx.browserless.unblock(props);
}
Loading
Loading