• This repository has been archived on 08/Jul/2023
  • Stars
    star
    798
  • Rank 57,078 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🦊 Node.js API to control Firefox

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(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

More Repositories

1

hocs

🍱 Higher-Order Components for React
JavaScript
2,023
star
2

start

🔴 Functional task runner for Node.js
TypeScript
475
star
3

chromium-headless-remote

🐳 Dockerized Chromium in headless remote debugging mode
Makefile
125
star
4

isparta-loader

💯 isparta instrumenter loader for webpack
JavaScript
117
star
5

microjungle

🏭 HTML templating with JS. The Right Way.
JavaScript
91
star
6

baggage-loader

[MAINTAINER NEEDED] 👜 Webpack loader to automatically require any resources related to the required one
JavaScript
88
star
7

autopolyfiller-loader

🏭 Autopolyfiller loader for webpack
JavaScript
69
star
8

valya

✔️ Higher-Order Component for validation in React
JavaScript
63
star
9

Monokai-Soda-iTerm

🌈 Sublime Text 2 Soda Dark based theme for iTerm/iTerm2
47
star
10

mustache-loader

Mustache loader for webpack
JavaScript
39
star
11

mnth

📆 Calendar month as 2d array of Dates
TypeScript
38
star
12

babel-istanbul-loader

💯 babel-istanbul instrumenter loader for webpack
JavaScript
25
star
13

poncho

Client-side JS code coverage using PhantomJS, Mocha and Blanket
JavaScript
23
star
14

typeon

✔️ Typed JSON parse and stringify for TypeScript
TypeScript
22
star
15

jquery-pointerevents

Basic polyfill for Pointer Events W3C Specification
JavaScript
20
star
16

firefox-headless-remote

🐳 Dockerized Firefox in headless Marionette mode
JavaScript
16
star
17

markdown-highlight-loader

🏭 Markdown (marked + highlight.js) loader for webpack
JavaScript
11
star
18

babel-register-ts

🔧 @babel/register wrapper with additional .ts and .tsx extensions
JavaScript
10
star
19

mocku

🕶️ ESM mocking library
TypeScript
9
star
20

nbx

▶️ Execute package binaries
Shell
8
star
21

react-attrs-filter

Filter React props
JavaScript
8
star
22

copie

👯‍♀️ Copy a file
TypeScript
7
star
23

1pwd

🔑 1Password CLI wrapper
TypeScript
6
star
24

ungoogled-chromium-headless-remote

🐳 Dockerized Ungoogled Chromium in headless remote debugging mode
Dockerfile
6
star
25

auto

TypeScript
4
star
26

ekst

🔡 Append, prepend, replace or remove basename extensions
TypeScript
4
star
27

dleet

🔥 Delete directories and files
TypeScript
4
star
28

makethen

✨ Promisify Node.js-style callbacks with native Promise
TypeScript
4
star
29

codecov-node-lite

💯 LCOV uploader for codecov.io service
TypeScript
4
star
30

spyfn

👀 Spy function
TypeScript
4
star
31

flows

〰 A proof of concept of alternative Flow Library Definitions manager
JavaScript
4
star
32

eslint-config-tough

[ DEPRECATED ]
JavaScript
4
star
33

itc

iTunes ITC files parser and covers extractor
JavaScript
3
star
34

dba

Don't Be an Asshole
JavaScript
3
star
35

bsc

🔍 Binary search with comparator
TypeScript
3
star
36

lessbuildify

Browserify plugin for compiling Less to the external file
JavaScript
3
star
37

yocto

chainable all the default DOM Element methods and properties
JavaScript
3
star
38

_

⚙️ Personal configs, presets, etc
TypeScript
3
star
39

move-path

➡️ Move path to destination folder
TypeScript
3
star
40

get-local-ip

Get a local IP address from a specified network range
JavaScript
2
star
41

karma-saucelabs-browsers

Autoprefixer-like browsers matching for Karma + SauceLabs
JavaScript
2
star
42

grunt-freeport

🆓 Grunt task to get a free port number on localhost from specified range
JavaScript
2
star
43

txt

🚧 my WIP dreams
TypeScript
1
star
44

jquery-pointerpressrelease

Additional 'pointerpress' and 'pointerrelease' events on top of jquery-pointerevents
JavaScript
1
star
45

deepsweet

1
star
46

deepsweet.github.io

🌐
HTML
1
star
47

chrome.theoldreader.notifier

Displays the number of unread RSS items of The Old Reader
JavaScript
1
star