Ind.ie is now Small Technology Foundation.
Commit c023a902 authored by Stanley Shyiko's avatar Stanley Shyiko

Initial

parents
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
* text=auto
.idea
node_modules
.DS_Store*
.tmp
.idea
node_modules
.DS_Store*
.tmp
.gitattributes
.npmignore
#!/bin/bash
__dirname=$(cd ${0%/*} && pwd -P)
$__dirname/../node_modules/electron-prebuilt/cli.js src "$@"
Copyright (c) 2015 Stanley Shyiko
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
{
"name": "electron-har",
"description": "A command-line tool for generating HTTP Archive (HAR) (based on Electron)",
"version": "0.1.0",
"author": "Stanley Shyiko <stanley.shyiko@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/shyiko/electron-har"
},
"bin": "./bin/electron-har",
"dependencies": {
"yargs": "^3.31.0",
"json-stable-stringify": "^1.0.0",
"electron-prebuilt": "^0.35.4"
},
"scripts": {
"start-dev": "electron src --debug"
},
"keywords": [
"electron",
"har"
]
}
# electron-har
A command-line tool for generating HTTP Archive (HAR) (based on [Electron](http://electron.atom.io/)).
## Installation
```sh
npm install -g electron-har
```
## Usage
```sh
electron-har http://google.com > google_com.har
```
> 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)
<!DOCTYPE html>
<script src="index.js"></script>
var LOAD_INDICATOR = 'https://did-finish-load/';
chrome.devtools.network.onRequestFinished.addListener(function (request) {
if (request.request.url === LOAD_INDICATOR) {
chrome.devtools.network.getHAR(function (har) {
har.entries = har.entries.filter(function (e) {
return e.request.url !== LOAD_INDICATOR;
});
chrome.devtools.inspectedWindow.eval(
'require("electron").ipcRenderer.send("har-generation-succeeded", ' + JSON.stringify(har) + ');');
});
}
});
chrome.devtools.inspectedWindow.eval('require("electron").ipcRenderer.send("devtools-loaded");');
{
"name": "devtools-extension",
"description": "Electron HAR DevTools Extension",
"version": "0.1.0",
"manifest_version": 2,
"devtools_page": "index.html"
}
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('debug', 'Show GUI (useful for debugging)').boolean('debug')
.help('h').alias('h', 'help')
.version(function () { return require('../package').version; })
.strict();
var argv = yargs.argv;
var url = argv._[0];
if (argv.u) {
var usplit = argv.u.split(':');
var username = usplit[0];
var password = usplit[1] || '';
}
var debug = !!argv.debug;
var argvValidationError;
if (!url) {
argvValidationError = 'URL must be specified';
} else if (!/^(http|https|file):\/\//.test(url)) {
argvValidationError = 'URL must contain the protocol prefix, e.g. the http:// or file://.';
}
if (argvValidationError) {
yargs.showHelp();
console.error(argvValidationError);
process.exit(1);
}
var app = require('app');
var BrowserWindow = require('browser-window');
var stringify = require('json-stable-stringify');
app.commandLine.appendSwitch('disable-http-cache');
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);
});
}
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 () {
BrowserWindow.removeDevToolsExtension('devtools-extension');
BrowserWindow.addDevToolsExtension(__dirname + '/devtools-extension');
var bw = new BrowserWindow({show: debug});
bw.webContents.on('devtools-opened', function () {
function notifyDevToolsExtensionOfLoad() {
bw.webContents.executeJavaScript('new Image().src = "https://did-finish-load/"');
}
// fired regardless of the outcome (success or not)
bw.webContents.on('did-finish-load', notifyDevToolsExtensionOfLoad);
bw.webContents.on('did-fail-load', function (e, errorCode, errorDescription, url) {
if (url !== 'chrome://ensure-electron-resolution/' && url !== 'https://did-finish-load/') {
bw.webContents.removeListener('did-finish-load', notifyDevToolsExtensionOfLoad);
var err = new Error(errorDescription);
err.code = errorCode;
require('electron').ipcRenderer.send('har-generation-failed', err);
}
});
});
ipcMain.on('devtools-loaded', function (event) {
setTimeout(function () { bw.loadURL(url); }, 0);
});
bw.openDevTools();
// any url will do, but make sure to call loadURL before 'devtools-opened'.
// otherwise require('electron') within child BrowserWindow will (most likely) fail
bw.loadURL('chrome://ensure-electron-resolution/');
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment