Skip to content

New Components - browserbase #16714

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 6 commits into from
May 20, 2025
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
30 changes: 30 additions & 0 deletions components/browserbase/actions/create-context/create-context.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import browserbase from "../../browserbase.app.mjs";

export default {
key: "browserbase-create-context",
name: "Create Context",
description: "Creates a new context in Browserbase. [See the documentation](https://docs.browserbase.com/reference/api/create-a-context)",
version: "0.0.1",
type: "action",
props: {
browserbase,
projectId: {
propDefinition: [
browserbase,
"projectId",
],
},
},
async run({ $ }) {
const response = await this.browserbase.createContext({
$,
data: {
projectId: this.projectId,
},
});

$.export("$summary", `Successfully created context with ID: ${response.id}`);

return response;
},
};
83 changes: 83 additions & 0 deletions components/browserbase/actions/create-session/create-session.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import browserbase from "../../browserbase.app.mjs";
import { REGION_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "browserbase-create-session",
name: "Create Session",
description: "Creates a new browser session with specified settings. [See the documentation](https://docs.browserbase.com/reference/api/create-a-session)",
version: "0.0.1",
type: "action",
props: {
browserbase,
projectId: {
propDefinition: [
browserbase,
"projectId",
],
},
extensionId: {
type: "string",
label: "Extension ID",
description: "The uploaded Extension ID",
optional: true,
},
browserSettings: {
type: "object",
label: "Browser Settings",
description: "An object with the settings for the session. [See the documentation](https://docs.browserbase.com/reference/api/create-a-session#body-browser-settings) for more details.",
optional: true,
},
timeout: {
type: "integer",
label: "Timeout",
description: "Duration in seconds after which the session will automatically end.",
min: 60,
max: 21600,
optional: true,
},
keepAlive: {
type: "boolean",
label: "Keep Alive",
description: "Set to true to keep the session alive even after disconnections.",
optional: true,
},
proxies: {
type: "string[]",
label: "Proxies",
description: "An array of objects with proxy configuration. [See the documentation](https://docs.browserbase.com/reference/api/create-a-session#body-proxies) for more details.",
optional: true,
},
region: {
type: "string",
label: "Region",
description: "The region where the session should run.",
options: REGION_OPTIONS,
optional: true,
},
userMetadata: {
type: "object",
label: "User Metadata",
description: "Arbitrary user metadata to attach to the session. To learn more about user metadata, see [User Metadata](https://docs.browserbase.com/features/sessions#user-metadata).",
optional: true,
},
},
async run({ $ }) {
const response = await this.browserbase.createSession({
$,
data: {
projectId: this.projectId,
extensionId: this.extensionId,
browserSettings: parseObject(this.browserSettings),
timeout: this.timeout,
keepAlive: this.keepAlive,
proxies: parseObject(this.proxies),
region: this.region,
userMetadata: parseObject(this.userMetadata),
},
});

$.export("$summary", `Session created successfully with ID: ${response.id}`);
return response;
},
};
19 changes: 19 additions & 0 deletions components/browserbase/actions/list-projects/list-projects.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import browserbase from "../../browserbase.app.mjs";

export default {
key: "browserbase-list-projects",
name: "List Projects",
description: "Lists all projects. [See the documentation](https://docs.browserbase.com/reference/api/list-projects)",
version: "0.0.1",
type: "action",
props: {
browserbase,
},
async run({ $ }) {
const projects = await this.browserbase.listProjects({
$,
});
$.export("$summary", `Successfully listed ${projects.length} project(s).`);
return projects;
},
};
63 changes: 59 additions & 4 deletions components/browserbase/browserbase.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "browserbase",
propDefinitions: {},
propDefinitions: {
projectId: {
type: "string",
label: "Project ID",
description: "The ID of the project",
async options() {
const projects = await this.listProjects();
return projects.map((project) => ({
value: project.id,
label: project.name,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.browserbase.com/v1";
},
_headers() {
return {
"x-bb-api-key": `${this.$auth.api_key}`,
"Content-Type": "application/json",
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
listProjects(opts = {}) {
return this._makeRequest({
path: "/projects",
...opts,
});
},
listSessions(opts = {}) {
return this._makeRequest({
path: "/sessions",
...opts,
});
},
createSession(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/sessions",
...opts,
});
},
createContext(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/contexts",
...opts,
});
},
},
};
25 changes: 25 additions & 0 deletions components/browserbase/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const REGION_OPTIONS = [
{
label: "US West 2",
value: "us-west-2",
},
{
label: "US East 1",
value: "us-east-1",
},
{
label: "EU Central 1",
value: "eu-central-1",
},
{
label: "AP Southeast 1",
value: "ap-southeast-1",
},
];

export const STATUS_OPTIONS = [
"RUNNING",
"ERROR",
"TIMED_OUT",
"COMPLETED",
];
24 changes: 24 additions & 0 deletions components/browserbase/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
5 changes: 4 additions & 1 deletion components/browserbase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/browserbase",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Browserbase Components",
"main": "browserbase.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
61 changes: 61 additions & 0 deletions components/browserbase/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import browserbase from "../../browserbase.app.mjs";

export default {
props: {
browserbase,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || 0;
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
getParams() {
return {};
},
async emitEvent(maxResults = false) {
const lastDate = this._getLastDate();
const fn = this.getFunction();

const response = await fn({
params: this.getParams(),
});

let responseArray = response.filter((item) => {
return Date.parse(item.createdAt) > lastDate;
});

if (responseArray.length) {
if (maxResults && (responseArray.length > maxResults)) {
responseArray.length = maxResults;
}
this._setLastDate(Date.parse(responseArray[0].createdAt));
}

for (const item of responseArray.reverse()) {
this.$emit(item, {
id: item.id,
summary: this.getSummary(item),
ts: Date.parse(item.createdAt),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
};
45 changes: 45 additions & 0 deletions components/browserbase/sources/new-session/new-session.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { STATUS_OPTIONS } from "../../common/constants.mjs";
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "browserbase-new-session",
name: "New Session Created",
description: "Emit new event when a new session is created. [See the documentation](https://docs.browserbase.com/reference/api/list-sessions)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
...common.props,
status: {
type: "string",
label: "Status",
description: "The status of the session.",
options: STATUS_OPTIONS,
optional: true,
},
q: {
type: "string",
label: "Query",
description: "Query sessions by user metadata. See [Querying Sessions by User Metadata](https://docs.browserbase.com/features/sessions#querying-sessions-by-user-metadata) for the schema of this query.",
optional: true,
},
},
methods: {
...common.methods,
getFunction() {
return this.browserbase.listSessions;
},
getParams() {
return {
status: this.status,
q: this.q || null,
};
},
getSummary(item) {
return `New session: ${item.id}`;
},
},
sampleEmit,
};
Loading
Loading