Which version of PhantomJS are you using? Tip: run phantomjs --version.
2.1.1
What steps will reproduce the problem?
Running below code will result into blank image.
Which operating system are you using?
Ubuntu
Did you use binary PhantomJS or did you compile it from source?
Installed from following command - sudo apt install phantomjs
Please provide any additional information below.
I am trying to capture screen of my application using below code:
var page = require('webpage').create();
page.userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36';
page.open('https://securelearning.in', function() {
page.render('image.png');
phantom.exit();
});
But this results, into blank image.
Have you solved it now?
No. Still facing the same issue.
Can you paste your code here?
var page = require('webpage').create();
page.userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36';
page.open('https://securelearning.in', function() {
page.render('image.png');
phantom.exit();
});
@Dindrawat, @JustinYi922, one thing I can suggest it to wrap your code into setTimeout() to make sure the page has fully loaded before you actually take screenshot.
And wrap logic into try, catch block, because if you are using script on server environment it may happen that you will have phantomjs process frozen and it loads the server pretty hard. Even if you are using it locally on the computer for some scrapping, etc, it is useful to know if error encountered, etc.
...
page.open('https://securelearning.in', function() {
setTimeout(function() {
try {
page.render('image.png');
phantom.exit();
} catch(e) {
console.log('Error happened: ' + e.toString());
phantom.exit();
}
}, 6000); // Wait 6 secs and take screenshot
});
Ref: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
@bologer - We already tried, this but no luck :(
@Dindrawat, I will look at this problem tonight and let you know
@Dindrawat actually when I open the website https://securelearning.in in browser it really shows a blank page without anything or title. I'm using Safari on macOS.
I have a separate issue though using CasperJS/PhantomJS, after trying to log into mastodon.social it is blank dark grey page. That one I just brushed it off as maybe some incompatibility. After raised issue here for some time no response I closed.
@Dindrawat, @kensoh I am trying to find the solution, however it seems that the website is blocking PhantomJS requests and not displaying the content, however I still receive errors as the reply from the console (the same ones I see in the developer console in Chrome).
I think it is detecting PJS by something like the following: https://stackoverflow.com/a/24471222/3661795, but not sure exactly, we will need to figure out the way of getting around this.
Thanks @bologer for sharing! This is interesting :)
curious to know if there was ever any resolution to this? I'm running into the same issue.
From you guys experience, would it be easier to use another browser such as Chrome or Chrome headless which helps to get through websites detecting for automated browsers? I find that using Chrome seems to have higher compatibility as websites are mostly designed to work with it.
Any resolution for this issue/ i am facing the same issue still.
using browser - chrome above 78 version
Most helpful comment
@Dindrawat, @kensoh I am trying to find the solution, however it seems that the website is blocking PhantomJS requests and not displaying the content, however I still receive errors as the reply from the console (the same ones I see in the developer console in Chrome).
I think it is detecting PJS by something like the following: https://stackoverflow.com/a/24471222/3661795, but not sure exactly, we will need to figure out the way of getting around this.