Skip to content

Latest commit

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date

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

constplayfast=require("playfast");constpath=require("path");asyncfunctionmain(){constbrowser=awaitnewplayfast().launchPersistentContext(path.join(__dirname,"browser-profile"),{executablePath: path.join(__dirname,"chrome-win/chrome.exe")});constpage=awaitbrowser.newPage();awaitpage.goto("https://www.google.com");console.log(awaitpage.url());awaitbrowser.close();}main();

API Reference

new Playfast()

Creates a new Playfast instance.

constplayfast=require("playfast");constbrowserManager=newplayfast();

Browser

launchPersistentContext(userDataDir, options)

Launches a persistent Chromium instance.

Parameters:

ParameterTypeDescription
userDataDirstringPath to the user data directory
optionsobjectLaunch options

Supported Options:

OptionTypeDescription
executablePathstringPath to Chromium/Chrome executable
userAgentstringCustom user agent
timezoneIdstringTimezone to emulate
colorSchemestring"light" or "dark"
proxyobject{ server: "http://..." }
argsstring[]Additional command line arguments

Returns:Promise<Browser>

Browser Methods

MethodDescriptionReturns
newPage()Creates a new pagePromise<Page>
close()Closes the browserPromise<void>
cookies()Get all cookiesPromise<Array>
addCookies(cookies)Add cookiesPromise<void>
exposeFunction(name, fn)Expose a Node.js function to the browserPromise<void>
addInitScript(script)Add script that runs on every new documentPromise<void>

Events:

  • close — Emitted when the browser closes.

Page

Page Methods

MethodDescriptionReturns
goto(url)Navigate to a URLPromise<void>
url()Get current page URLPromise<string>
reload()Reload the current pagePromise<void>
evaluate(fn, ...args)Execute JavaScript in the page contextPromise<any>
getSelector(selector)Get a selector objectPromise<Selector>
close()Close the pagePromise<void>
requestGC()Trigger garbage collectionPromise<void>
scriptParsed(fn)Listen for parsed scripts (advanced)-
paused(fn)Listen for debugger pauses (advanced)-

Page Events

EventDescription
loadPage finished loading
requestfailedA network request failed
websocketWebSocket connection created
websocketReceivedWebSocket message received

Selector

Selector Methods

MethodDescriptionReturns
evaluate(fn, ...args)Execute function in the context of the elementPromise<any>

Example: Evaluate & Selectors

constpage=awaitbrowser.newPage();awaitpage.goto("https://example.com");// Run JavaScriptconsttitle=awaitpage.evaluate(()=>document.title);// Work with elementsconstbutton=awaitpage.getSelector("button.login");awaitbutton.evaluate(el=>el.click());

About

Lightweight Chromium driver for NodeJS

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages