0.49.1 • Published 5 months ago
@hyperbrowser/sdk v0.49.1
Hyperbrowser Node SDK
Checkout the full documentation here
Installation
Hyperbrowser can be installed via npm by running:
npm install @hyperbrowser/sdk
or
yarn add @hyperbrowser/sdk
Usage
Playwright
import { chromium } from "playwright-core";
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { config } from "dotenv";
config();
const client = new Hyperbrowser({
apiKey: process.env.HYPERBROWSER_API_KEY,
});
const main = async () => {
const session = await client.sessions.create();
try {
const browser = await chromium.connectOverCDP(session.wsEndpoint);
const defaultContext = browser.contexts()[0];
const page = await defaultContext.newPage();
// Navigate to a website
console.log("Navigating to Hacker News...");
await page.goto("https://news.ycombinator.com/");
const pageTitle = await page.title();
console.log("Page 1:", pageTitle);
await page.evaluate(() => {
console.log("Page 1:", document.title);
});
await page.goto("https://example.com");
console.log("Page 2:", await page.title());
await page.evaluate(() => {
console.log("Page 2:", document.title);
});
await page.goto("https://apple.com");
console.log("Page 3:", await page.title());
await page.evaluate(() => {
console.log("Page 3:", document.title);
});
await page.goto("https://google.com");
console.log("Page 4:", await page.title());
await page.evaluate(() => {
console.log("Page 4:", document.title);
});
} catch (err) {
console.error(`Encountered error: ${err}`);
} finally {
await client.sessions.stop(session.id);
}
};
main();
Puppeteer
import { connect } from "puppeteer-core";
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { config } from "dotenv";
config();
const client = new Hyperbrowser({
apiKey: process.env.HYPERBROWSER_API_KEY,
});
const main = async () => {
const session = await client.sessions.create();
try {
const browser = await connect({
browserWSEndpoint: session.wsEndpoint,
defaultViewport: null,
});
const [page] = await browser.pages();
// Navigate to a website
console.log("Navigating to Hacker News...");
await page.goto("https://news.ycombinator.com/");
const pageTitle = await page.title();
console.log("Page 1:", pageTitle);
await page.evaluate(() => {
console.log("Page 1:", document.title);
});
await page.goto("https://example.com");
console.log("Page 2:", await page.title());
await page.evaluate(() => {
console.log("Page 2:", document.title);
});
await page.goto("https://apple.com");
console.log("Page 3:", await page.title());
await page.evaluate(() => {
console.log("Page 3:", document.title);
});
await page.goto("https://google.com");
console.log("Page 4:", await page.title());
await page.evaluate(() => {
console.log("Page 4:", document.title);
});
} catch (err) {
console.error(`Encountered error: ${err}`);
} finally {
await client.sessions.stop(session.id);
}
};
main();
0.49.1
5 months ago
0.49.0
5 months ago
0.48.1
5 months ago
0.48.0
6 months ago
0.47.0
6 months ago
0.46.0
6 months ago
0.45.0
6 months ago
0.44.3
6 months ago
0.44.0
6 months ago
0.43.0
7 months ago
0.42.0
7 months ago
0.41.0
7 months ago
0.40.0
7 months ago
0.39.0
7 months ago
0.38.0
7 months ago
0.37.0
7 months ago
0.36.0
7 months ago
0.35.0
7 months ago
0.34.0
8 months ago
0.33.0
8 months ago
0.32.0
8 months ago
0.31.0
8 months ago
0.30.0
8 months ago
0.29.0
9 months ago
0.28.0
9 months ago
0.27.0
9 months ago
0.26.0
9 months ago
0.25.0
9 months ago
0.24.0
9 months ago
0.23.0
9 months ago
0.22.0
9 months ago
0.21.0
9 months ago
0.20.0
9 months ago
0.19.0
9 months ago
0.18.0
9 months ago
0.17.0
9 months ago
0.16.0
10 months ago
0.15.0
10 months ago
0.14.0
10 months ago
0.13.0
10 months ago
0.12.0
10 months ago
0.11.0
10 months ago
0.10.0
10 months ago
0.9.0
10 months ago
0.8.0
10 months ago
0.7.0
10 months ago
0.6.0
11 months ago
0.5.0
11 months ago
0.4.0
11 months ago
0.3.0
11 months ago
0.2.0
11 months ago
0.1.0
11 months ago