diff --git a/mincss/download.js b/mincss/download.js index 5956480..2d16701 100644 --- a/mincss/download.js +++ b/mincss/download.js @@ -1,6 +1,23 @@ +var system = require('system'); var page = require('webpage').create(); -page.open(phantom.args[0], function () { - //page.render('screenshot.png'); - console.log(page.content); - phantom.exit(); +page.viewportSize = {width: 1280, height: 1024}; +page.settings.resourceTimeout = 5000; +page.onResourceTimeout = function(e) { + console.log(e.errorCode); // it'll probably be 408 + console.log(e.errorString); // it'll probably be 'Network timeout on resource' + console.log(e.url); // the url whose request timed out + phantom.exit(2); +}; +var url = system.args[1] +page.open(url, function (status) { + if (status !== 'success') { + console.log('Unable to load', url); + phantom.exit(1); + } else { + setTimeout(function() { + page.render('screenshot.png'); + console.log(page.content); + phantom.exit(0); + }, 1000) + } }); diff --git a/mincss/processor.py b/mincss/processor.py index de4d924..fc045a4 100644 --- a/mincss/processor.py +++ b/mincss/processor.py @@ -114,11 +114,13 @@ def download(self, url): def download_with_phantomjs(self, url): if self.phantomjs is True: # otherwise, assume it's a path - self.phantomjs = 'phantomjs' + phantomjs = 'phantomjs' elif not os.path.isfile(self.phantomjs): raise IOError('%s is not a path to phantomjs' % self.phantomjs) + else: + phantomjs = self.phantomjs - command = [self.phantomjs] + command = [phantomjs] if self.phantomjs_options: if 'load-images' not in self.phantomjs_options: # not entirely sure if this helps but there can't be any point