@benmalka/foxdriver

中文文档
0.6.0发布于 2021/02/02Apache-2.0CommonJS近 30 天下载 3467

Foxdriver is a Node library which provides a high-level API to control Firefox over the Remote Debugging Protocol

原始使用文档
文档目录5 节
  1. Getting Started
  2. Installation
  3. Usage
  4. API
  5. Foxdriver

Foxdriver

Foxdriver is a Node library which provides a high-level API to control Firefox over the Remote Debugging Protocol. Version 0.6.0 now supports adding custom profile files (i.e. cert9.db) before launching the browser

Getting Started

Installation

To use Foxdriver in your project, run:

$ npm i @benmalka/foxdriver

Usage

The Firefox Remote Debugging Protocol consists of multiple actors that provide different methods. The Foxdriver API allows you to launch a Firefox instance and connects to the protocol interface automatically. From there you can access the methods of all actors.

Example - opening page and get console.logs

import Foxdriver from '@benmalka/foxdriver'

(async () => {
    const { browser, tab } = await Foxdriver.launch({
        url: 'https://www.mozilla.org/en-US'
    });

    // enable actor
    await tab.console.startListeners();
    // wait until page is loaded
    await new Promise((resolve) => setTimeout(resolve, 3000));
    // receive logs and page errors
    const logs = await tab.console.getCachedMessages();
    console.log(logs);

    // close browser
    browser.close();
})()

You can also attach yourself to an already running Firefox browser. This requires to start the browser with the -start-debugger-server=<port> cli argument and have the following settings set:

  • devtools.chrome.enabled: true
  • devtools.debugger.prompt-connection: false
  • devtools.debugger.remote-enabled: true

To attach yourself to the browser you then need to create a Foxdriver instance with the correct port and host and call the connect() method:

import Foxdriver from '@benmalka/foxdriver'

(async () => {
    const { browser, tab } = await Foxdriver.attach('localhost', 9222);
    const preferences = await browser.preference.getAllPrefs();

    // ...
})()

API

Foxdriver

Foxdriver.attach(host, port)

Attaches client to an already running instance.

  • host <String> host where Firefox instance was launched
  • port <Number> port on which the Firefox instance was launched
  • returns: <Promise<Object>>
    • tab <[Tab]> list of opened tabs
    • browser <Browser> browser instance

Foxdriver.launch(options)

Attaches client to an already running instance.

  • options <Object>
    • port <Number> port on which the Firefox instance should get launched
    • bin <String> path to Firefox binary (default: OS default path)
    • args <[String]> list of arguments pass to fs.spawn (default: [])
    • customPrefs <Object> you may set your own preferences before the browser is being launched by setting key value pairs of prefs. Note that it is not possible to override the required prefs, i.e.
      • devtools.chrome.enabled: true
      • devtools.debugger.prompt-connection: false
      • devtools.debugger.remote-enabled: true
    • customProfileFiles <[String]> A array of absolute file paths to be copied into the randomaly generated profile folder. This is very helpful when working with self-signed certificates in firefox. See more here How to use self-signed certificate in Firefox
  • returns: <Promise<Object>>
    • tab <Tab> opened tab
    • browser <Browser> browser instance

class: Browser

close()

Disconnects from the browser instance and closes browser if launched via launch() method

class: Tab

tab.attach()

Attaches to this tab

  • returns: <Promise> fulfills once request was sent
tab.detach()

Detaches from this tab

  • returns: <Promise> fulfills once request was sent
tab.reload()

Reloads current page url.

  • returns: <Promise> fulfills once request was sent
tab.cacheDisabled(disable)

Disable cache.

  • disable <Boolean> if true, caching is disbled
  • returns: <Promise> fulfills once request was sent
tab.navigateTo(url)

Navigates to a certain url

  • url <String> url to navigate to
  • returns: <Promise> fulfills once request was sent
tab.onTabNavigated(callback)

Event fired on tab navigation end

  • callback <Function> to be called on event

For more information please see API docs.

版本与发布记录

@benmalka/foxdriver 共发布 13 个版本,首次发布于 2019/11/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.0latest2021/02/025 年前
0.5.02020/10/116 年前
0.4.32020/09/076 年前
0.4.22020/09/016 年前
0.4.12020/06/306 年前
0.4.02020/03/226 年前

关于 @benmalka/foxdriver 的常见问题

@benmalka/foxdriver 是什么?

Foxdriver is a Node library which provides a high-level API to control Firefox over the Remote Debugging Protocol

如何安装 @benmalka/foxdriver?

在项目目录运行 npm install @benmalka/foxdriver,或使用 pnpm add / yarn add / bun add。

@benmalka/foxdriver 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/benmalka__foxdriver 是否存在。

@benmalka/foxdriver 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@benmalka/foxdriver 可以商用吗?

@benmalka/foxdriver 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@benmalka/foxdriver 的下载量有多少?

根据 npm 官方下载统计,@benmalka/foxdriver 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,467 次,日均约 116 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@benmalka/foxdriver 还在维护吗?

最新版本 0.6.0 发布于 2021/02/02(5 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/11/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。