Need private packages and team management tools?Check out npm Teams »

foxr

0.10.1 • Public • Published

foxr

npm install size tests coverage

Node.js API to control Firefox.

logo

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
import foxr from 'foxr'
// const foxr = require('foxr').default
 
(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)
  }
})()

Install

yarn add --dev foxr
# or 
npm install --save-dev foxr

API

Foxr

connect

Connect to the Marionette endpoint.

type TConnectOptions = {
  host?: string,
  port?: number,
  defaultViewport?: {
    width?: number,
    height?: number
  }
}
 
foxr.connect(options?: TConnectOptions)Promise<Browser>
  • host'localhost' by default
  • port2828 by default
  • defaultViewport
    • width800 by default
    • height600 by default

launch

type TLaunchOptions = {
  args?: string[],
  dumpio?: boolean,
  executablePath: string,
  headless?: boolean
} & TConnectOptions
 
foxr.launch(options?: TLaunchOptions)Promise<Browser>
  • args – array of additional args, ['-marionette', '-safe-mode', '-no-remote'] by default
  • dumpio – print browser process stdout and stderr, false by default
  • executablePath – path to Firefox executable, required
  • headless – 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.install(extensionPathstring, isTemporaryboolean)Promise<string | null>

uninstall

browser.install(extensionIdstring)Promise<void>

getPref

browser.getPref(prefstring, defaultBranchboolean = false)Promise<any>

setPref

browser.setPref(prefstring, valuestring | number | boolean, defaultBranchboolean = false)Promise<void>

Page

$

page.$(selectorstring)Promise<ElementHandle | null>

$$

page.$$(selectorstring)Promise<ElementHandle[]>

$eval

page.$eval(selectorstring, funcTSerializableFunction, ...argsTEvaluateArg[])Promise<TJsonValue | void>

$$eval

page.$$eval(selectorstring, funcTSerializableFunction, ...argsTEvaluateArg[])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.evaluate(targetstring)Promise<TJsonValue | void>
page.evaluate(targetTSerializableFunction, ...argsTEvaluateArg[])Promise<TJsonValue | void>

evaluateHandle

page.evaluate(targetstring)Promise<JSHandle>
page.evaluate(targetTSerializableFunction, ...argsTEvaluateArg[])Promise<JSHandle>

focus

page.focus(selectorstring)Promise<void>

goto

page.goto(urlstring)Promise<void>

screenshot

page.screenshot(options?: { path?: string })Promise<Buffer>

setContent

page.setContent(htmlstring)Promise<void>

title

page.title()Promise<string>

url

page.url()Promise<string>

viewport

page.viewport()Promise<{ widthnumber, heightnumber }>

JSHandle

ElementHandle

$

elementHandle.$(selectorstring)Promise<ElementHandle | null>

$$

elementHandle.$$(selectorstring)Promise<ElementHandle[]>

click

type TOptions = {
  button?: 'left' | 'middle' | 'right',
  clickCount?: number
}
 
elementHandle.click(options?: TOptions)Promise<void>

focus

elementHandle.focus()Promise<void>

hover

elementHandle.hover()Promise<void>

press

elementHandle.press(keystring)Promise<void>

Where key is of the possible keys or a single character.

screenshot

elementHandle.screenshot(options?: { path?: string })Promise<Buffer>

type

elementHandle.type(textstring)Promise<void>

Development

See my Start task runner preset for details.

References

Install

npm i foxr

DownloadsWeekly Downloads

215

Version

0.10.1

License

MIT

Unpacked Size

44 kB

Total Files

27

Last publish

Collaborators

  • avatar