Awesome Open Source
Awesome Open Source

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
  • port ā€“ 2828 by default
  • defaultViewport
    • width ā€“ 800 by default
    • height ā€“ 600 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(extensionPath: string, isTemporary: boolean): Promise<string | null>

uninstall

browser.install(extensionId: string): Promise<void>

getPref

browser.getPref(pref: string, defaultBranch: boolean = false): Promise<any>

setPref

browser.setPref(pref: string, value: string | number | boolean, defaultBranch: boolean = false): Promise<void>

Page

$

page.$(selector: string): Promise<ElementHandle | null>

$$

page.$$(selector: string): Promise<ElementHandle[]>

$eval

page.$eval(selector: string, func: TSerializableFunction, ...args: TEvaluateArg[]): Promise<TJsonValue | void>

$$eval

page.$$eval(selector: 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.evaluate(target: string): Promise<TJsonValue | void>
page.evaluate(target: TSerializableFunction, ...args: TEvaluateArg[]): Promise<TJsonValue | void>

evaluateHandle

page.evaluate(target: string): Promise<JSHandle>
page.evaluate(target: TSerializableFunction, ...args: TEvaluateArg[]): Promise<JSHandle>

focus

page.focus(selector: string): Promise<void>

goto

page.goto(url: string): Promise<void>

screenshot

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

setContent

page.setContent(html: string): Promise<void>

title

page.title(): Promise<string>

url

page.url(): Promise<string>

viewport

page.viewport(): Promise<{ width: number, height: number }>

JSHandle

ā€¦

ElementHandle

$

elementHandle.$(selector: string): Promise<ElementHandle | null>

$$

elementHandle.$$(selector: string): 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(key: string): Promise<void>

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

screenshot

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

type

elementHandle.type(text: string): Promise<void>

Development

See my Start task runner preset for details.

References


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
typescript (10,876)Ā 
firefox (305)Ā 
selenium (208)Ā 
puppeteer (151)Ā 
headless (98)Ā 
remote (74)Ā 

Find Open Source By Browsing 7,000 Topics Across 59 Categories

Advertising šŸ“¦Ā 10
All Projects
Application Programming Interfaces šŸ“¦Ā 124
Applications šŸ“¦Ā 192
Artificial Intelligence šŸ“¦Ā 78
Blockchain šŸ“¦Ā 73
Build Tools šŸ“¦Ā 113
Cloud Computing šŸ“¦Ā 80
Code Quality šŸ“¦Ā 28
Collaboration šŸ“¦Ā 32
Command Line Interface šŸ“¦Ā 49
Community šŸ“¦Ā 83
Companies šŸ“¦Ā 60
Compilers šŸ“¦Ā 63
Computer Science šŸ“¦Ā 80
Configuration Management šŸ“¦Ā 42
Content Management šŸ“¦Ā 175
Control Flow šŸ“¦Ā 213
Data Formats šŸ“¦Ā 78
Data Processing šŸ“¦Ā 276
Data Storage šŸ“¦Ā 135
Economics šŸ“¦Ā 64
Frameworks šŸ“¦Ā 215
Games šŸ“¦Ā 129
Graphics šŸ“¦Ā 110
Hardware šŸ“¦Ā 152
Integrated Development Environments šŸ“¦Ā 49
Learning Resources šŸ“¦Ā 166
Legal šŸ“¦Ā 29
Libraries šŸ“¦Ā 129
Lists Of Projects šŸ“¦Ā 22
Machine Learning šŸ“¦Ā 347
Mapping šŸ“¦Ā 64
Marketing šŸ“¦Ā 15
Mathematics šŸ“¦Ā 55
Media šŸ“¦Ā 239
Messaging šŸ“¦Ā 98
Networking šŸ“¦Ā 315
Operating Systems šŸ“¦Ā 89
Operations šŸ“¦Ā 121
Package Managers šŸ“¦Ā 55
Programming Languages šŸ“¦Ā 245
Runtime Environments šŸ“¦Ā 100
Science šŸ“¦Ā 42
Security šŸ“¦Ā 396
Social Media šŸ“¦Ā 27
Software Architecture šŸ“¦Ā 72
Software Development šŸ“¦Ā 72
Software Performance šŸ“¦Ā 58
Software Quality šŸ“¦Ā 133
Text Editors šŸ“¦Ā 49
Text Processing šŸ“¦Ā 136
User Interface šŸ“¦Ā 330
User Interface Components šŸ“¦Ā 514
Version Control šŸ“¦Ā 30
Virtualization šŸ“¦Ā 71
Web Browsers šŸ“¦Ā 42
Web Servers šŸ“¦Ā 26
Web User Interface šŸ“¦Ā 210