Closed clubh closed 4 years ago
Do you know if and how it would be possible with the phantomjs
renderer ?
This might be possible with this function for Phantomjs.
I imagine this feature as a --customjs <file>
option for webscreenshot
, where <file>
would contain Javascript code to be evaluated before taking a screenshot.
Feature added in v2.94 with the --custom-js
option.
As a proof, I managed to edit the background color of a page:
The executed command:
$ python3 webscreenshot.py -vv "https://archive.apache.org/dist/tomcat/" --custom-js js.txt
Content of js.txt
function(){
document.body.bgColor = 'red';
}
The screenshot performed
I'm trying to make use of this feature to accept Google's cookie policy. When I execute the (JS-newbie) script in the browser console, it works (which isn't much of a surprise, given that I run it after I see the page completely loaded...), but when I run it using webscreenshot, it doesn't. This is how I run it:
$ python3 webscreenshot.py -v --custom-js pre-shot.js 'https://www.google.com/maps/@45.9001957,15.9519309,14.5z'
....and this is the script:
function(){
var numRes = 0;
do {
var iAgreeClass = "VfPpkd-vQzf8d"
numRes = document.getElementsByClassName(iAgreeClass);
} while (numRes < 8); // wait for the button to appear; there should be 8 elements of this class when it's loaded
var iAgreeButton = document.getElementsByClassName(iAgreeClass)[3]; // the 3rd button is the one I'm interested in
iAgreeButton.click();
}
Any clues/suggestions?
Would be nice to be able to pass CSS or JS to the webpage to hide cookie notifications.