Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
forks
electron-har
Commits
40e88d53
Commit
40e88d53
authored
Apr 24, 2016
by
Aral Balkan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a timeout for HAR generation.
parent
943f5a78
Pipeline
#301
skipped
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
src/index.js
src/index.js
+16
-2
No files found.
src/index.js
View file @
40e88d53
...
...
@@ -15,7 +15,10 @@ var spawn = require('cross-spawn-async');
* @param {function(err, json)} callback callback (NOTE: if err != null err.code will be the exit code (e.g. 3 - wrong usage,
* 4 - timeout, below zero - http://src.chromium.org/svn/trunk/src/net/base/net_error_list.h))
*/
module
.
exports
=
function
electronHAR
(
url
,
options
,
callback
)
{
module
.
exports
=
function
electronHAR
(
url
,
options
,
timeout
,
callback
)
{
if
(
timeout
==
undefined
)
{
timeout
=
0
;
}
typeof
options
===
'
function
'
&&
(
callback
=
options
,
options
=
{});
// Using temporary file to prevent messages like "Xlib: extension ...",
...
...
@@ -54,6 +57,9 @@ module.exports = function electronHAR(url, options, callback) {
// The callback for the spawned process.
var
processCallback
=
function
(
err
,
stdout
,
stderr
)
{
if
(
timeoutID
!=
null
)
{
clearTimeout
(
timeoutID
);
}
if
(
err
)
{
if
(
stderr
)
{
err
.
message
=
stderr
.
trim
();
...
...
@@ -77,11 +83,19 @@ module.exports = function electronHAR(url, options, callback) {
// Initialise the electron-har process using spawn
// as cross-exec-file (exec-file) results in stdout maxBuffer exceeded errors.
var
command
=
spawn
(
__dirname
+
'
/../bin/electron-har
'
,
args
)
var
command
=
spawn
(
__dirname
+
'
/../bin/electron-har
'
,
args
,
{
detached
:
true
}
)
var
result
=
''
command
.
stdout
.
on
(
'
data
'
,
function
(
data
){
result
+=
data
.
toString
();
})
command
.
on
(
'
close
'
,
processCallback
)
var
timeoutID
=
null
if
(
timeout
>
0
)
{
timeoutID
=
setTimeout
(
function
()
{
process
.
kill
(
-
command
.
pid
,
'
SIGINT
'
)
},
timeout
*
1000
);
}
});
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment