New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

electron-har

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-har - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

{
"name": "electron-har",
"description": "A command-line tool for generating HTTP Archive (HAR) (based on Electron)",
"version": "0.1.2",
"version": "0.1.3",
"author": "Stanley Shyiko <stanley.shyiko@gmail.com>",

@@ -6,0 +6,0 @@ "license": "MIT",

# electron-har
A command-line tool for generating HTTP Archive (HAR) (based on [Electron](http://electron.atom.io/)).
A command-line tool for generating [HTTP Archive (HAR)](http://www.softwareishard.com/blog/har-12-spec/) (based on [Electron](http://electron.atom.io/)).
The data you get is identical to "Save All as HAR" from the Network pane of Developer Tools in Chromium.
## Installation

@@ -14,9 +16,13 @@

```sh
electron-har http://google.com > google_com.har
electron-har http://google.com # writes HAR to stdout
# in a headless environment (CI agent on Linux?) - xvfb-run will do just fine
DISPLAY=:1 xvfb-run electron-har http://google.com -o google_com.har
# to see a complete list of command line options
electron-har --help
```
> To see a complete list of command line options try `electron-har --help`.
## License
[MIT License](https://github.com/shyiko/electron-har/blob/master/mit.license)
var yargs = require('yargs')
.usage('Usage: electron-har [options...] <url>')
// NOTE: when adding an option - keep it compatible with `curl` (if possible)
.describe('u', 'User [and password] divided by colon').alias('u', 'user').nargs('u', 1)
.describe('u', 'Username and password (divided by colon)').alias('u', 'user').nargs('u', 1)
.describe('o', 'Write to file instead of stdout').alias('o', 'output').nargs('o', 1)
.describe('m', 'Maximum time allowed for HAR generation (in seconds)').alias('m', 'max-time').nargs('m', 1)
.describe('debug', 'Show GUI (useful for debugging)').boolean('debug')

@@ -17,2 +19,4 @@ .help('h').alias('h', 'help')

}
var outputFile = argv.output;
var timeout = parseInt(argv.m, 10);
var debug = !!argv.debug;

@@ -32,29 +36,43 @@

var electron = require('electron');
var app = require('app');
var BrowserWindow = require('browser-window');
var stringify = require('json-stable-stringify');
var fs = require('fs');
if (timeout > 0) {
setTimeout(function () {
console.error('Timed out waiting for the HAR');
debug || app.exit(2);
}, timeout * 1000);
}
app.commandLine.appendSwitch('disable-http-cache');
app.dock.hide();
app.on('window-all-closed', function () {
app.quit();
});
app.dock && app.dock.hide();
app.on('window-all-closed', function () { app.quit(); });
if (username) {
app.on('login', function (event, webContents, request, authInfo, callback) {
event.preventDefault();
callback(username, password);
electron.ipcMain
.on('har-generation-succeeded', function (sender, event) {
var har = stringify(event, {space: 2});
if (outputFile) {
fs.writeFile(outputFile, har, function (err) {
if (err) {
console.error(err.message);
debug || app.exit(1);
return;
}
debug || app.quit();
});
} else {
console.log(har);
debug || app.quit();
}
})
.on('har-generation-failed', function (sender, event) {
console.error('An attempt to generate HAR resulted in error code ' + event.errorCode +
(event.errorDescription ? ' (' + event.errorDescription + ')' : '') +
'. \n(error codes defined in http://src.chromium.org/svn/trunk/src/net/base/net_error_list.h)');
debug || app.exit(event.errorCode);
});
}
var ipcMain = require('electron').ipcMain;
ipcMain.on('har-generation-succeeded', function (sender, event) {
console.log(stringify(event, {space: 2}));
debug || app.quit();
});
ipcMain.on('har-generation-failed', function (sender, event) {
console.error(stringify(event, {space: 2}));
debug || app.exit(1);
});
app.on('ready', function () {

@@ -67,2 +85,9 @@

if (username) {
bw.webContents.on('login', function (event, request, authInfo, cb) {
event.preventDefault(); // default behavior is to cancel auth
cb(username, password);
});
}
bw.webContents.on('devtools-opened', function () {

@@ -79,5 +104,4 @@ function notifyDevToolsExtensionOfLoad() {

bw.webContents.removeListener('did-finish-load', notifyDevToolsExtensionOfLoad);
var err = new Error(errorDescription);
err.code = errorCode;
require('electron').ipcRenderer.send('har-generation-failed', err);
bw.webContents.executeJavaScript('require("electron").ipcRenderer.send("har-generation-failed", ' +
JSON.stringify({errorCode: errorCode, errorDescription: errorDescription}) + ')');
}

@@ -87,3 +111,3 @@ });

ipcMain.on('devtools-loaded', function (event) {
electron.ipcMain.on('devtools-loaded', function (event) {
setTimeout(function () { bw.loadURL(url); }, 0);

@@ -90,0 +114,0 @@ });