{"id":13565530,"url":"https://github.com/cyrus-and/chrome-har-capturer","last_synced_at":"2025-05-14T14:08:20.049Z","repository":{"id":5866034,"uuid":"7083204","full_name":"cyrus-and/chrome-har-capturer","owner":"cyrus-and","description":"Capture HAR files from a Chrome instance","archived":false,"fork":false,"pushed_at":"2025-02-18T09:51:49.000Z","size":321,"stargazers_count":544,"open_issues_count":1,"forks_count":91,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-04-11T21:05:50.830Z","etag":null,"topics":["automation","browser","chrome-debugging-protocol","google-chrome","har","headless","http-archive"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cyrus-and.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-12-09T20:31:17.000Z","updated_at":"2025-04-01T12:51:17.000Z","dependencies_parsed_at":"2022-09-26T20:20:58.832Z","dependency_job_id":"f59b084d-40c6-46b7-ab00-f5e8ebf68253","html_url":"https://github.com/cyrus-and/chrome-har-capturer","commit_stats":{"total_commits":308,"total_committers":7,"mean_commits":44.0,"dds":"0.038961038961038974","last_synced_commit":"2ecc4f89238612b6879afcc0d1389dce2dcbc0d7"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus-and%2Fchrome-har-capturer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus-and%2Fchrome-har-capturer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus-and%2Fchrome-har-capturer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus-and%2Fchrome-har-capturer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cyrus-and","download_url":"https://codeload.github.com/cyrus-and/chrome-har-capturer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159760,"owners_count":22024564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","browser","chrome-debugging-protocol","google-chrome","har","headless","http-archive"],"created_at":"2024-08-01T13:01:49.445Z","updated_at":"2025-05-14T14:08:20.029Z","avatar_url":"https://github.com/cyrus-and.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# chrome-har-capturer\n\n[![CI status](https://github.com/cyrus-and/chrome-har-capturer/actions/workflows/ci.yml/badge.svg)](https://github.com/cyrus-and/chrome-har-capturer/actions?query=workflow:CI)\n\nCapture HAR files from a Chrome instance.\n\nUnder the hood this module uses [chrome-remote-interface] to instrument Chrome.\n\n![Screenshot](http://i.imgur.com/HoDaGr3.png)\n\n## Setup\n\nInstall this module from NPM:\n\n```\nnpm install chrome-har-capturer\n```\n\nStart Chrome like this:\n\n```\ngoogle-chrome --remote-debugging-port=9222 --headless\n```\n\n## Command line utility\n\nThe command line utility can be used to generate HAR files from a list of URLs. The following options are available:\n\n    -h, --help               output usage information\n    -t, --host \u003chost\u003e        Chrome Debugging Protocol host\n    -p, --port \u003cport\u003e        Chrome Debugging Protocol port\n    -x, --width \u003cdip\u003e        frame width in DIP\n    -y, --height \u003cdip\u003e       frame height in DIP\n    -o, --output \u003cfile\u003e      write to file instead of stdout\n    -c, --content            also capture the requests body\n    -k, --cache              allow caching\n    -a, --agent \u003cagent\u003e      user agent override\n    -b, --block \u003cURL\u003e        URL pattern (*) to block (can be repeated)\n    -H, --header \u003cheader\u003e    Additional headers (can be repeated)\n    -i, --insecure           ignore certificate errors\n    -g, --grace \u003cms\u003e         time to wait after the load event\n    -u, --timeout \u003cms\u003e       time to wait before giving up with a URL\n    -r, --retry \u003cnumber\u003e     number of retries on page load failure\n    -e, --retry-delay \u003cms\u003e   time to wait before starting a new attempt\n    -f, --abort-on-failure   stop after the first failure (incompatible with parallel mode)\n    -d, --post-data \u003cbytes\u003e  maximum POST data size to be returned\n    -l, --parallel \u003cn\u003e       load \u003cn\u003e URLs in parallel\n\n## Library\n\nAlternatively this module provides a simple [API](#api) that can be used to write custom applications. See the command line utility [source code][] for a working example.\n\n[source code]: https://github.com/cyrus-and/chrome-har-capturer/blob/master/bin/cli.js\n\n### API\n\n#### run(urls, [options])\n\nStart the loading of a batch of URLs. Returns an event emitter (see below for the list of supported events).\n\n`urls` is array of URLs.\n\n`options` is an object with the following optional properties:\n\n- `host`: [Chrome Debugging Protocol][] host. Defaults to `localhost`;\n- `port`: [Chrome Debugging Protocol][] port. Defaults to `9222`;\n- `width`: frame width in DIP. Defaults to a Chrome-defined value;\n- `height`: frame height in DIP. Defaults to a Chrome-defined value;\n- `content`: if `true` also capture the requests body. Defaults to `false`;\n- `cache`: if `true` allow caching. Defaults to `false`;\n- `timeout`: milliseconds to wait before giving up with a URL;\n- `retry`: number of retries on page load failure. Defaults to `0`;\n- `retryDelay`: time to wait before starting a new attempt. Defaults to `0`;\n- `abortOnFailure`: stop after the first failure (incompatible with parallel mode);\n- `postData`: maximum POST data size (in bytes) to be returned. Defaults to unlimited;\n- `parallel`: if `true` load the URLs in parallel (**warning:** this may spoil time-based metrics). Defaults to `false`;\n- `preHook`: function returning a Promise executed before each page load:\n    - `url`: the current URL;\n    - `client`: [CDP client instance][];\n    - `index`: index of `url` in `urls`;\n    - `urls`: input URL array.\n- `postHook`: function returning a Promise executed after each page load event:\n    - `url`: the current URL;\n    - `client`: [CDP client instance][];\n    - `index`: index of `url` in `urls`;\n    - `urls`: input URL array.\n\n    If this hook resolves to a value then it is included in the resulting HAR object as the value of the `_user` key of the this URL's page object.\n\n[CDP client instance]: https://github.com/cyrus-and/chrome-remote-interface#class-cdp\n\n##### Event: 'load'\n\n```js\nfunction (url, index, urls) {}\n```\n\nEmitted when Chrome is about to load `url`. `index` is the index of `url` in `urls`. `urls` is the array passed to `run()`.\n\n##### Event: 'done'\n\n```js\nfunction (url, index, urls) {}\n```\n\nEmitted when Chrome finished loading `url`. `index` is the index of `url` in `urls`. `urls` is the array passed to `run()`.\n\n##### Event: fail'\n\n```js\nfunction (url, err, index, urls) {}\n```\n\nEmitted when Chrome cannot load `url`. The `Error` object `err` contains the failure reason. Failed URLs will not appear in the resulting HAR object. `index` is the index of `url` in `urls`. `urls` is the array passed to `run()`.\n\n##### Event: 'har'\n\n```js\nfunction (har) {}\n```\n\nEmitted when all the URLs have been processed. If all the URLs fails then a valid empty HAR object is returned. `har` is the resulting HAR object.\n\n#### fromLog(url, log, [options])\n\nGenerate a single-page HAR from an array of raw events that comes from the [Chrome Debugging Protocol][] (e.g., from [chrome-remote-interface][]). Returns a Promise that fulfills to the generated HAR.\n\n`url` is the page URL;\n\n`log` is the array of events in the form:\n\n```js\n{\n    method: '...',\n    params: {...}\n}\n```\n\nEvents to be provided are:\n\n- `Page.domContentEventFired`;\n- `Page.loadEventFired`;\n- `Network.requestWillBeSent`;\n- `Network.dataReceived`;\n- `Network.responseReceived`;\n- `Network.resourceChangedPriority`;\n- `Network.loadingFinished`;\n- `Network.loadingFailed`.\n\nAdditional events for WebSockets are:\n\n - `Network.webSocketWillSendHandshakeRequest`;\n - `Network.webSocketHandshakeResponseReceived`;\n - `Network.webSocketClosed`;\n - `Network.webSocketFrameSent`;\n - `Network.webSocketFrameReceived`.\n\n`options` is an object with the following optional properties:\n- `content`: if `true` also expect the requests body. Defaults to `false`.\n\nWhen `content` is `true` synthetic events in the following form are also expected:\n\n```js\n{\n    method: 'Network.getResponseBody',\n    params: {\n        requestId: '...',\n        body: '...',\n        base64Encoded: true/false\n    }\n}\n```\n\nThese events contain the reply of the [`Network.getResponseBody`][] method, this is needed because Chrome does not return the body content via events, instead it must be requested manually and the reply must be appended to the other events in the log.\n\n[`Network.getResponseBody`]: https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-getResponseBody\n\n## Resources\n\n- [HAR 1.2 Spec](http://www.softwareishard.com/blog/har-12-spec/)\n- [HAR Viewer](http://www.softwareishard.com/blog/har-viewer/)\n- [HAR Analyzer](https://toolbox.googleapps.com/apps/har_analyzer/)\n\n[Chrome Debugging Protocol]: https://developer.chrome.com/devtools/docs/debugger-protocol\n[chrome-remote-interface]: https://github.com/cyrus-and/chrome-remote-interface\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyrus-and%2Fchrome-har-capturer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyrus-and%2Fchrome-har-capturer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyrus-and%2Fchrome-har-capturer/lists"}