Verified Commit e1ecdc4b authored by Aral Balkan's avatar Aral Balkan
Browse files

Merge branch 'headless-chrome'

parents 72c443e0 c23683de
......@@ -20,7 +20,7 @@ zlib = require 'zlib'
gzipAsync = Promise.promisify zlib.gzip
gunzipAsync = Promise.promisify zlib.gunzip
generateArchiveFromURL = Promise.promisify (require 'electron-har')
chromeHarCapturer = require 'chrome-har-capturer'
fileSize = require 'file-size'
jsonStableStringify = require 'json-stable-stringify'
......@@ -64,13 +64,34 @@ class HTTPArchive
# If the URL does not have a protocol, default to HTTP.
if url.indexOf('http') != 0 then url = "http://#{url}"
return (generateArchiveFromURL url, {'user-agent': 'IPHONE_6', 'debug': debug}, timeout).catch (error) ->
if error == 3
throw new Error "Protocol missing/incorrect in URL (#{url})"
else if error.toString() is 'SyntaxError: Unexpected end of input'
throw new Error "Timed out"
else
throw new Error "Could not generate HAR file for #{url}. Error: #{error}."
#
# Chrome HAR Capturer uses events. Our design expects a promise here. So wrap it in a promise.
#
# iPhone 6/6s/7/8 screen size in pts (same as DIPs are per https://developers.google.com/speed/docs/insights/ConfigureViewport) from https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
# Set a post hook to wait 10 seconds after page load as a grace period to allow other scripts/trackers to load.
allowGraceTime = (url, client) ->
return new Promise (fulfill, reject) ->
setTimeout fulfill, 10000
return new Promise (resolve, reject) ->
(chromeHarCapturer.run [url], {
'agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1',
'timeout': 60000, # Timeout attempts after a minute
'width': 375, # iPhone 6/6s/7/8 resolution
'height': 667, # …
'postHook': allowGraceTime # Allow grace period after document load event
})
.on 'fail', reject
.on 'har', (har) -> resolve har
# return (generateArchiveFromURL url, {'user-agent': 'IPHONE_6', 'debug': debug}, timeout).catch (error) ->
# if error == 3
# throw new Error "Protocol missing/incorrect in URL (#{url})"
# else if error.toString() is 'SyntaxError: Unexpected end of input'
# throw new Error "Timed out"
# else
# throw new Error "Could not generate HAR file for #{url}. Error: #{error}."
# Promises to load an HTTP Archive file from the passed file path.
......
This diff is collapsed.
......@@ -3,6 +3,9 @@
"version": "1.0.0",
"description": "Investigator tools for Better.",
"main": "index.coffee",
"engines": {
"node": ">=7.6.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
......@@ -13,7 +16,7 @@
"buffer-equal": "^1.0.0",
"cli-spinner": "^0.2.5",
"easy-table": "^1.0.0",
"electron-har": "git+https://source.ind.ie/forks/electron-har.git",
"chrome-har-capturer": "git+https://source.ind.ie/forks/chrome-har-capturer.git",
"file-size": "^1.0.0",
"fs-extra": "^0.26.7",
"json-stable-stringify": "^1.0.1",
......
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