foxr
Node.js API to control Firefox.
- uses a built-in Marionette through remote protocol
- no Selenium WebDriver is needed
- works with Headless mode
- compatible subset of Puppeteer API
At this point Foxr is more a proof of concept, work is pretty much in progress.
Example
Run a locally installed Firefox:
/path/to/firefox -headless -marionette -safe-mode
Or a dockerized version:
docker run -it --rm --shm-size 2g -p 2828:2828 deepsweet/firefox-headless-remote:68
// const foxr = require('foxr').default async { try const browser = await foxr const page = await browser await page await page await browser catch error console }
Install
yarn add --dev foxr# or npm install --save-dev foxr
API
Foxr
connect
Connect to the Marionette endpoint.
host
–'localhost'
by defaultport
–2828
by defaultdefaultViewport
width
–800
by defaultheight
–600
by default
launch
args
– array of additional args,['-marionette', '-safe-mode', '-no-remote']
by defaultdumpio
– print browser process stdout and stderr,false
by defaultexecutablePath
– path to Firefox executable, requiredheadless
– whether to run browser in headless mode,true
by default
Browser
close
browser.close: Promise<void>
disconnect
browser.disconnect: Promise<void>
newPage
browser.newPage: Promise<Page>
pages
browser.pages: Promise<Page>
install
browser.installextensionPath: string, isTemporary: boolean: Promise<string | null>
uninstall
browser.installextensionId: string: Promise<void>
getPref
browser.getPrefpref: string, defaultBranch: boolean = false: Promise<any>
setPref
browser.setPrefpref: string, value: string | number | boolean, defaultBranch: boolean = false: Promise<void>
Page
$
page.$selector: string: Promise<ElementHandle | null>
$$
page.$$selector: string: Promise<ElementHandle>
$eval
page.$evalselector: string, func: TSerializableFunction, ...args: TEvaluateArg: Promise<TJsonValue | void>
$$eval
page.$$evalselector: string, func: TSerializableFunction, ...args: TEvaluateArg: Promise<Array<TJsonValue | void>>
bringToFront
page.bringToFront: Promise<void>
browser
page.browser: TBrowser
close
page.close: Promise<void>
content
page.content: Promise<string>
evaluate
page.evaluatetarget: string: Promise<TJsonValue | void>page.evaluatetarget: TSerializableFunction, ...args: TEvaluateArg: Promise<TJsonValue | void>
evaluateHandle
page.evaluatetarget: string: Promise<JSHandle>page.evaluatetarget: TSerializableFunction, ...args: TEvaluateArg: Promise<JSHandle>
focus
page.focusselector: string: Promise<void>
goto
page.gotourl: string: Promise<void>
screenshot
page.screenshotoptions?: : Promise<Buffer>
setContent
page.setContenthtml: string: Promise<void>
title
page.title: Promise<string>
url
page.url: Promise<string>
viewport
page.viewport: Promise<>
JSHandle
…
ElementHandle
$
elementHandle.$selector: string: Promise<ElementHandle | null>
$$
elementHandle.$$selector: string: Promise<ElementHandle>
click
focus
elementHandle.focus: Promise<void>
hover
elementHandle.hover: Promise<void>
press
elementHandle.presskey: string: Promise<void>
Where key
is of the possible keys or a single character.
screenshot
elementHandle.screenshotoptions?: : Promise<Buffer>
type
elementHandle.typetext: string: Promise<void>
Development
See my Start task runner preset for details.