Foxdriver is a Node library which provides a high-level API to control Firefox over the Remote Debugging Protocol
npm install @benmalka/foxdriverFoxdriver
=========
> 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
sh
$ npm i @benmalka/foxdriver
`
$3
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
`js
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= 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:
`js
import Foxdriver from '@benmalka/foxdriver'
(async () => {
const { browser, tab } = await Foxdriver.attach('localhost', 9222);
const preferences = await browser.preference.getAllPrefs();
// ...
})()
`
API
- Foxdriver
* class: Foxdriver
+ Foxdriver.attach(options)
+ Foxdriver.launch(options)
* class: Browser
+ browser.close()
+ browser.preference
+ browser.actorRegistry
+ browser.addons
+ browser.device
+ browser.heapSnapshotFile
* class: Tab
+ tab.attach()
+ tab.detach()
+ tab.reload()
+ tab.cacheDisabled(disable)
+ tab.navigateTo(url)
+ tab.onTabNavigated(callback)
+ tab.console
+ tab.network
+ tab.storage
+ tab.memory
+ tab.performance
+ tab.profiler
+ tab.timeline
+ tab.styleSheets
+ tab.cssUsage
+ tab.cssProperties
+ tab.emulation
+ tab.inspector
$3
#### Foxdriver.attach(host, port)
Attaches client to an already running instance.
- host host where Firefox instance was launched
- port port on which the Firefox instance was launched
- returns:
- tab <[Tab]> list of opened tabs
- browser browser instance
#### Foxdriver.launch(options)
Attaches client to an already running instance.
- options