const system = require('system')
const page = require('webpage').create()

var args = system.args
var exitTimer = null


page.viewportSize = {
	width: 375,
	height: 667
}
page.settings.resourceTimeout = 60000
page.settings.XSSAuditingEnabled = true
page.settings.loadImages = false
page.settings.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1'

page.onConsoleMessage = function (msg) {
	if (msg == ':phatomexit') {
		// clearTimeout(exitTimer)
		// phantom.exit()
	}
}

page.onLoadFinished = function (status) {
	clearTimeout(exitTimer)
	exitTimer = setTimeout(function () {
		phantom.exit()
	}, 10000)
}

page.onResourceReceived = function (response) {
	if (response.url && response.url.length < 2000) {
		console._log(response.url)
	}
	clearTimeout(exitTimer)
	exitTimer = setTimeout(function () {
		phantom.exit()
	}, 10000)
}

console._log = console.log
console.info = console.error = console.log = function () {}
page.open(decodeURIComponent(args[1]))
