Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/loadmill/har-recorder
Capture HAR recordings from Chrome sessions or Selenium tests using Node.js
https://github.com/loadmill/har-recorder
chrome-debugging-protocol har nodejs selenium
Last synced: 4 months ago
JSON representation
Capture HAR recordings from Chrome sessions or Selenium tests using Node.js
- Host: GitHub
- URL: https://github.com/loadmill/har-recorder
- Owner: loadmill
- License: mit
- Created: 2019-12-09T12:25:40.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-08T09:18:28.000Z (over 1 year ago)
- Last Synced: 2024-09-27T14:40:56.954Z (4 months ago)
- Topics: chrome-debugging-protocol, har, nodejs, selenium
- Language: JavaScript
- Homepage: https://www.loadmill.com/
- Size: 276 KB
- Stars: 12
- Watchers: 4
- Forks: 5
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# har-recorder
Use this package to capture HAR recordings from Chrome sessions or Selenium tests.
Using the [Chrome Debugging Protocol](https://chromedevtools.github.io/devtools-protocol/) thorugh [chrome-remote-interface](https://github.com/cyrus-and/chrome-remote-interface) this pakcage listens to Chrome Fetch events and stores requests and reponses to HAR file.
## Selenium usage example
```javascript
const { startRecording, endRecording } = HarRecorder();// enable chrome remote debugging on port 9223
let chrome_options = new chrome.Options()
.addArguments("--remote-debugging-port=9223");driver = await new Builder()
.setChromeOptions(chrome_options)
.forBrowser('chrome')
.build();// start the recording on port 9223
await startRecording({ port: 9223 });// do Selenium stuff
await driver.navigate().to('https://www.google.com');
await driver.wait(until.elementLocated(By.name('q')));// save recording to file
endRecording('create-blog-post.har');
driver.quit();
```## Installation
npm install har-recorder
## Setup
An instance of either Chrome itself or another implementation needs to be
running on a known port in order to use this module (defaults to
`localhost:9222`).## API
The API consists of three parts:
- The constructor function which creates a new HarRecorder.
- `startRecording([options])` which starts recording a given Chrome instance. The recording defaults to
`localhost:9222`. Overide this by passing a [CDP options object](https://github.com/cyrus-and/chrome-remote-interface/blob/master/README.md#cdpoptions-callback).- `endRecording(filePath)` which saves the HAR recording to a file and resets the stored requests.