Last active
April 29, 2019 23:45
-
-
Save atamsingh/70717db3c7f3d506eb5aab5ea1014407 to your computer and use it in GitHub Desktop.
Performance Timing Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webserver = require('webserver'); | |
var system = require('system'); | |
function urlToAddress(url_string) { | |
var rx = /address=(.+?)(&|$)/gm; | |
var arr = rx.exec(url_string); | |
return arr[1] | |
} | |
var server = webserver.create(); | |
console.log('starting server...') | |
var service = server.listen('0.0.0.0:80', function(request, response) { | |
url = urlToAddress(request.url); | |
var page = require('webpage').create(); | |
page.clearMemoryCache(); | |
window.setTimeout(function(){ | |
response.statusCode = 408; | |
response.write(""); | |
response.close(); | |
page.close(); | |
}, 20000); | |
page.open(url, function (status) { | |
if (status == 'success'){ | |
window.setTimeout(function () { | |
var webpage_navigation_data = page.evaluate(function(){ | |
return JSON.stringify(window.performance.timing); | |
}) | |
response.statusCode = 200; | |
response.write(webpage_navigation_data); | |
response.close(); | |
}, 7000); | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment