Skip to content
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,4 @@ jobs:
- name: Run e2e tests
env:
BROWSERBASE_API_KEY: ${{ secrets.BB_INTEGRATION_TEST_API_KEY }}
BROWSERBASE_PROJECT_ID: ${{ secrets.BB_INTEGRATION_TEST_PROJECT_ID }}
run: pnpm run test:e2e
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ pnpm dlx @browserbasehq/sdk-functions init my-project
cd my-project
```

Add your Browserbase credentials to `.env`:
Add your Browserbase API key to `.env`:

```sh
BROWSERBASE_API_KEY=your_api_key_here
BROWSERBASE_PROJECT_ID=your_project_id_here
```

Start the local development server:
Expand Down Expand Up @@ -188,14 +187,13 @@ Options:

## Configuration

Set your Browserbase credentials as environment variables or in a `.env` file:
Set your Browserbase API key as an environment variable or in a `.env` file:

| Variable | Required | Description |
| ------------------------ | -------- | --------------------------- |
| `BROWSERBASE_API_KEY` | Yes | Your Browserbase API key |
| `BROWSERBASE_PROJECT_ID` | Yes | Your Browserbase project ID |
| Variable | Required | Description |
| --------------------- | -------- | ------------------------ |
| `BROWSERBASE_API_KEY` | Yes | Your Browserbase API key |

Get your API key and project ID from [browserbase.com](https://browserbase.com).
Get your API key from [browserbase.com](https://browserbase.com).

## Requirements

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@browserbasehq/sdk-functions",
"version": "1.0.1",
"version": "1.0.2",
"description": "",
"type": "module",
"exports": {
Expand Down Expand Up @@ -60,7 +60,7 @@
"typescript-eslint": "^8.42.0"
},
"dependencies": {
"@browserbasehq/sdk": "^2.6.0",
"@browserbasehq/sdk": "^2.10.0",
"archiver": "^7.0.1",
"chalk": "^5.6.2",
"commander": "^14.0.2",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 2 additions & 21 deletions src/cli/dev/browser-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ export interface IRemoteBrowserManager {
*/
closeSession(sessionId: string): Promise<void>;

/**
* Get the project ID
*/
getProjectId(): string;

/**
* Check if the manager is initialized
*/
Expand All @@ -45,28 +40,23 @@ export interface IRemoteBrowserManager {
*/
export class RemoteBrowserManager implements IRemoteBrowserManager {
private browserbaseClient: Browserbase | null = null;
private projectId: string;
private apiKey: string;
private initialized: boolean = false;

constructor() {
const foundProjectId = process.env["BROWSERBASE_PROJECT_ID"];
const foundApiKey = process.env["BROWSERBASE_API_KEY"];

if (!foundProjectId || !foundApiKey) {
if (!foundApiKey) {
console.error(
chalk.red("✗ Browserbase credentials not found.\n") +
chalk.red(
" Please set BROWSERBASE_PROJECT_ID and BROWSERBASE_API_KEY in your .env file.\n",
) +
chalk.red(" Please set BROWSERBASE_API_KEY in your .env file.\n") +
chalk.gray(
" Copy .env.example to .env and fill in your credentials.",
),
);
throw new Error("Missing Browserbase credentials");
}

this.projectId = foundProjectId;
this.apiKey = foundApiKey;
}

Expand Down Expand Up @@ -98,7 +88,6 @@ export class RemoteBrowserManager implements IRemoteBrowserManager {
console.log(chalk.cyan(`Creating browser session...`));

const createdSession = await this.browserbaseClient.sessions.create({
projectId: this.projectId,
...sessionConfig,
});

Expand All @@ -122,7 +111,6 @@ export class RemoteBrowserManager implements IRemoteBrowserManager {
try {
console.log(chalk.cyan(`Closing browser session: ${sessionId}...`));
await this.browserbaseClient.sessions.update(sessionId, {
projectId: this.projectId,
status: "REQUEST_RELEASE",
});
console.log(chalk.green(`✓ Browser session closed: ${sessionId}`));
Expand All @@ -135,13 +123,6 @@ export class RemoteBrowserManager implements IRemoteBrowserManager {
}
}

/**
* Get the project ID
*/
public getProjectId(): string {
return this.projectId;
}

/**
* Check if the manager is initialized
*/
Expand Down
4 changes: 0 additions & 4 deletions src/cli/dev/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ class MockBrowserManager implements IRemoteBrowserManager {
this.closeSessionCalls.push([sessionId]);
}

getProjectId(): string {
return "test-project-id";
}

isInitialized(): boolean {
return true;
}
Expand Down
5 changes: 1 addition & 4 deletions src/cli/init/templates/.env.template
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Browserbase Configuration
# Get your API key and project ID from https://browserbase.com
# Get your API key from https://browserbase.com

# Your Browserbase API key
BROWSERBASE_API_KEY=your_api_key_here

# Your Browserbase project ID
BROWSERBASE_PROJECT_ID=your_project_id_here
1 change: 0 additions & 1 deletion src/cli/invoke/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
export interface InvocationResponse {
id: string;
functionId: string;
projectId: string;
status: InvocationStatus;
params?: Record<string, unknown>;
results?: Record<string, unknown>;
Expand Down
6 changes: 0 additions & 6 deletions src/cli/publish/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {

export interface BuildMetadata {
entrypoint: string;
projectId?: string;
}

export interface UploadResult {
Expand All @@ -21,7 +20,6 @@ export interface UploadResult {

export interface FunctionCreatedVersion {
id: string;
projectId: string;
functionId: string;
functionBuildId: string;
sessionCreateParams?: Record<string, unknown>;
Expand All @@ -31,7 +29,6 @@ export interface FunctionCreatedVersion {

export interface BuiltFunction {
id: string;
projectId: string;
name: string;
createdVersion: FunctionCreatedVersion;
createdAt: string;
Expand All @@ -40,7 +37,6 @@ export interface BuiltFunction {

export interface BuildStatusResponse {
id: string;
projectId: string;
status: BuildStatus;
request: {
entrypoint: string;
Expand All @@ -63,7 +59,6 @@ export async function uploadBuild(
if (options?.dryRun) {
console.log(chalk.cyan("\n[Dry run] Would upload to:"));
console.log(chalk.gray(` URL: ${config.apiUrl}/v1/functions/builds`));
console.log(chalk.gray(` Project ID: ${config.projectId}`));
console.log(chalk.gray(` Entrypoint: ${config.entrypoint}`));
console.log(
chalk.gray(
Expand All @@ -85,7 +80,6 @@ export async function uploadBuild(
// Add metadata
const metadata: BuildMetadata = {
entrypoint: config.entrypoint,
projectId: config.projectId,
};
formData.append("metadata", JSON.stringify(metadata));

Expand Down
4 changes: 0 additions & 4 deletions src/cli/publish/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as path from "node:path";
import {
type BaseConfig,
requireApiKey,
requireProjectId,
getApiUrl,
validateApiKeyFormat,
} from "../shared/index.js";
Expand All @@ -14,7 +13,6 @@ import {
* Extended configuration for publish command.
*/
export interface PublishConfig extends BaseConfig {
projectId: string;
entrypoint: string;
workingDirectory: string;
}
Expand All @@ -24,7 +22,6 @@ export function loadConfig(options: {
apiUrl?: string;
}): PublishConfig {
const apiKey = requireApiKey();
const projectId = requireProjectId();
const apiUrl = getApiUrl(options.apiUrl);

// Use provided entrypoint or default to main.ts
Expand Down Expand Up @@ -52,7 +49,6 @@ export function loadConfig(options: {

return {
apiKey,
projectId,
apiUrl,
entrypoint,
workingDirectory: process.cwd(),
Expand Down
4 changes: 1 addition & 3 deletions src/cli/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function displayBuildDetails(build: BuildStatusResponse): void {

// Display basic build information
console.log(chalk.white(`Build ID: ${chalk.cyan(build.id)}`));
console.log(chalk.white(`Project ID: ${chalk.cyan(build.projectId)}`));
console.log(chalk.white(`Status: ${chalk.green(build.status)}`));

if (build.request?.entrypoint) {
Expand Down Expand Up @@ -101,7 +100,7 @@ function displayBuildDetails(build: BuildStatusResponse): void {
console.log(chalk.gray("\n curl --request POST \\"));
console.log(
chalk.gray(
` --url ${func.projectId ? "https" : "http"}://api.browserbase.com/v1/functions/${func.id}/invoke \\`,
` --url https://api.browserbase.com/v1/functions/${func.id}/invoke \\`,
),
);
console.log(
Expand Down Expand Up @@ -138,7 +137,6 @@ export async function publishFunction(options: PublishOptions): Promise<void> {
console.log(chalk.gray(`Working directory: ${config.workingDirectory}`));
console.log(chalk.gray(`Entrypoint: ${config.entrypoint}`));
console.log(chalk.gray(`API URL: ${config.apiUrl}`));
console.log(chalk.gray(`Project ID: ${config.projectId}`));

if (options.dryRun) {
console.log(
Expand Down
22 changes: 0 additions & 22 deletions src/cli/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ export function requireApiKey(): string {
return apiKey;
}

/**
* Get the Browserbase project ID from environment.
* Exits the process with an error message if not found.
*/
export function requireProjectId(): string {
const projectId = process.env["BROWSERBASE_PROJECT_ID"];
if (!projectId) {
console.error(
chalk.red(
"Error: BROWSERBASE_PROJECT_ID not found in environment variables.",
),
);
console.log(
chalk.gray(
"Please set BROWSERBASE_PROJECT_ID in your .env file or environment.",
),
);
process.exit(1);
}
return projectId;
}

/**
* Get the API URL from options, environment, or use the default.
*/
Expand Down
1 change: 0 additions & 1 deletion src/cli/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export {
type BaseConfig,
requireApiKey,
requireProjectId,
getApiUrl,
validateApiKeyFormat,
loadBaseConfig,
Expand Down
4 changes: 2 additions & 2 deletions src/define/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("buildPersistedFunctionManifest", () => {
parametersSchema: schema,
sessionConfig: {
browserSettings: {
fingerprint: { devices: ["desktop"] },

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer in latest version of SDK

blockAds: true,
},
},
},
Expand All @@ -81,7 +81,7 @@ describe("buildPersistedFunctionManifest", () => {
assert(result.config.parametersSchema);
assert.deepStrictEqual(result.config.sessionConfig, {
browserSettings: {
fingerprint: { devices: ["desktop"] },
blockAds: true,
},
});
});
Expand Down
3 changes: 0 additions & 3 deletions tests/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
requireCredentials,
pollBuildStatus,
API_KEY,
PROJECT_ID,
discoverTemplates,
getTarballPath,
setupTemplateProject,
Expand Down Expand Up @@ -63,7 +62,6 @@ describe("E2E: Publish, Build, and Invoke", { concurrency: true }, () => {
env: {
...process.env,
BROWSERBASE_API_KEY: API_KEY,
BROWSERBASE_PROJECT_ID: PROJECT_ID,
},
stdio: ["pipe", "pipe", "pipe"],
},
Expand Down Expand Up @@ -114,7 +112,6 @@ describe("E2E: Publish, Build, and Invoke", { concurrency: true }, () => {
env: {
...process.env,
BROWSERBASE_API_KEY: API_KEY,
BROWSERBASE_PROJECT_ID: PROJECT_ID,
},
stdio: ["pipe", "pipe", "pipe"],
timeout: 120_000,
Expand Down
7 changes: 2 additions & 5 deletions tests/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ dotenv.config({ path: join(PROJECT_ROOT_LOCAL, ".env.e2e") });
// ── Credentials ──────────────────────────────────────────────────

export const API_KEY = process.env["BROWSERBASE_API_KEY"];
export const PROJECT_ID = process.env["BROWSERBASE_PROJECT_ID"];
export const API_URL =
process.env["BROWSERBASE_API_URL"] ?? "https://api.browserbase.com";

export function requireCredentials(): void {
if (!API_KEY || !PROJECT_ID) {
throw new Error(
"BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID must be set for e2e tests",
);
if (!API_KEY) {
throw new Error("BROWSERBASE_API_KEY must be set for e2e tests");
}
}

Expand Down
Loading
Loading