Node.js API to control Firefox.
- uses a built-in Marionette through remote protocol
- no Selenium WebDriver is needed
- works with Headless mode
- similar to compatible to Puppeteer API*
*At this point Foxr is more a working proof of concept. Although the goal is to have a fully compatible to Puppeteer API, or at least a subset of it, the work is pretty much in progress.
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:61
import foxr from 'foxr'
(async () => {
try {
const browser = await foxr.connect()
const page = await browser.newPage()
await page.goto('https://example.com')
await page.screenshot({ path: 'example.png' })
await browser.close()
} catch (error) {
console.error(error)
}
})()
- Node.js >= 6
esm
loader
yarn add --dev foxr
# or
npm install --dev foxr
Connect to the Marionette endpoint.
type TOptions = {
host?: string,
port?: number
}
foxr.connect(options?: TOptions): Promise<TBrowser>
host
–'localhost'
by defaultport
–2828
by default
browser.close(): Promise<void>
browser.disconnect(): Promise<void>
browser.newPage(): Promise<TPage>
browser.pages(): Promise<TPage[]>
page.$(selector: string): Promise<TElement>
page.$$(selector: string): Promise<TElement[]>
page.close(): Promise<void>
type TAnyJson = boolean | number | string | null | TJsonArray | TJsonMap
interface TJsonMap { [key: string]: TAnyJson }
interface TJsonArray extends Array<TAnyJson> {}
type TSerializableFunction = (...args: TAnyJson[]) => TAnyJson
page.evaluate(target: TSerializableFunction | string): Promise<TAnyJson>
page.goto(url: string): Promise<void>
type TOptions = {
path?: string
}
page.screenshot(options?: TOptions): Promise<Buffer>
page.setContent(html: string): Promise<void>
page.title(): Promise<string>
element.$(selector: string): Promise<TElement>
element.$$(selector: string): Promise<TElement[]>
type TOptions = {
path?: string
}
element.screenshot(options?: TOptions): Promise<Buffer>
See my Start task runner preset for details.