<commit_before>nightmare-har-plugin
====================

[![Build Status](https://travis-ci.org/alexbardas/nightmare-har-plugin.svg?branch=master)](https://travis-ci.org/alexbardas/nightmare-har-plugin)

[Nightmare](https://nightmarejs.org) plugin that uses the [electron](http://electron.atom.io) devtools to capture network activity in HAR (HTTP Archive) format.

It extends the nightmare behaviour with 2 extra methods: `getHAR()` and `waitForDevtools()`. It also contains a chrome devtools extension used to retrieve the network activity.

### Nightmare extended API
##### `.waitForDevtools()`
Waits for devtools to open so all network requests can be captured. If not executed before the first `goto()` method, the first requests may be lost because of the async behavior of opening the devtools.

##### `.getHAR()`
Retrives the HAR information as a json.

### Plugin API
##### `.install(Nightmare)`
Installs the extra methods using the Nightmare's `action` API.

##### `.getDevtoolsOptions()`
Returns an object with some default devtools options Nightmare needs in order to open devtools shortly after initialization.


### Usage:

```
let Nightmare = require('nightmare')
let harPlugin = require('nightmare-har-plugin')

harPlugin.install(Nightmare)

let options = {
  waitTimeout: 1000
}

let nightmare = Nightmare(Object.assign(harPlugin.getDevtoolsOptions(), options))

nightmare
  .waitForDevtools()
  .goto('http://news.ycombinator.com')
  .wait('#hnmain')
  .getHAR()<commit_msg>Include js syntax highlighting in Readme<commit_after>nightmare-har-plugin
====================

[![Build Status](https://travis-ci.org/alexbardas/nightmare-har-plugin.svg?branch=master)](https://travis-ci.org/alexbardas/nightmare-har-plugin)

[Nightmare](https://nightmarejs.org) plugin that uses the [electron](http://electron.atom.io) devtools to capture network activity in HAR (HTTP Archive) format.

It extends the nightmare behaviour with 2 extra methods: `getHAR()` and `waitForDevtools()`. It also contains a chrome devtools extension used to retrieve the network activity.

### Nightmare extended API
##### `.waitForDevtools()`
Waits for devtools to open so all network requests can be captured. If not executed before the first `goto()` method, the first requests may be lost because of the async behavior of opening the devtools.

##### `.getHAR()`
Retrives the HAR information as a json.

### Plugin API
##### `.install(Nightmare)`
Installs the extra methods using the Nightmare's `action` API.

##### `.getDevtoolsOptions()`
Returns an object with some default devtools options Nightmare needs in order to open devtools shortly after initialization.


### Usage:

```js
let Nightmare = require('nightmare')
let harPlugin = require('nightmare-har-plugin')

harPlugin.install(Nightmare)

let options = {
  waitTimeout: 1000
}

let nightmare = Nightmare(Object.assign(harPlugin.getDevtoolsOptions(), options))

nightmare
  .waitForDevtools()
  .goto('http://news.ycombinator.com')
  .wait('#hnmain')
  .getHAR()
{'fraction_non_alphanumeric': 0.13466003316749586, 'fraction_numerical': 0.003316749585406302, 'mean_word_length': 5.417021276595745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5763221', 'n_tokens_mistral': 911, 'n_tokens_neox': 841, 'n_words': 291}