npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

foxr

v0.10.1

Published

Node.js API to control Firefox

Downloads

575

Readme

foxr

npm install size tests coverage

Node.js API to control Firefox.

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