Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Playfast

Playfast is a lightweight Chromium driver built for Node.js. It provides a simple API for controlling Chromium using the Chrome DevTools Protocol.

Installation

npm install playfast

Quick Example

const playfast = require("playfast");
const path = require("path");

async function main() {
    const browser = await new playfast().launchPersistentContext(
        path.join(__dirname, "browser-profile"),
        {
            executablePath: path.join(__dirname, "chrome-win/chrome.exe")
        }
    );

    const page = await browser.newPage();
    await page.goto("https://www.google.com");

    console.log(await page.url());
    await browser.close();
}

main();

API Reference

new Playfast()

Creates a new Playfast instance.

const playfast = require("playfast");
const browserManager = new playfast();

Browser

launchPersistentContext(userDataDir, options)

Launches a persistent Chromium instance.

Parameters:

Parameter Type Description
userDataDir string Path to the user data directory
options object Launch options

Supported Options:

Option Type Description
executablePath string Path to Chromium/Chrome executable
userAgent string Custom user agent
timezoneId string Timezone to emulate
colorScheme string "light" or "dark"
proxy object { server: "http://..." }
args string[] Additional command line arguments

Returns: Promise<Browser>

Browser Methods

Method Description Returns
newPage() Creates a new page Promise<Page>
close() Closes the browser Promise<void>
cookies() Get all cookies Promise<Array>
addCookies(cookies) Add cookies Promise<void>
exposeFunction(name, fn) Expose a Node.js function to the browser Promise<void>
addInitScript(script) Add script that runs on every new document Promise<void>

Events:

  • close — Emitted when the browser closes.

Page

Page Methods

Method Description Returns
goto(url) Navigate to a URL Promise<void>
url() Get current page URL Promise<string>
reload() Reload the current page Promise<void>
evaluate(fn, ...args) Execute JavaScript in the page context Promise<any>
getSelector(selector) Get a selector object Promise<Selector>
close() Close the page Promise<void>
requestGC() Trigger garbage collection Promise<void>
scriptParsed(fn) Listen for parsed scripts (advanced) -
paused(fn) Listen for debugger pauses (advanced) -

Page Events

Event Description
load Page finished loading
requestfailed A network request failed
websocket WebSocket connection created
websocketReceived WebSocket message received

Selector

Selector Methods

Method Description Returns
evaluate(fn, ...args) Execute function in the context of the element Promise<any>

Example: Evaluate & Selectors

const page = await browser.newPage();
await page.goto("https://example.com");

// Run JavaScript
const title = await page.evaluate(() => document.title);

// Work with elements
const button = await page.getSelector("button.login");
await button.evaluate(el => el.click());

About

Lightweight Chromium driver for NodeJS

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages