maaaaz / webscreenshot

A simple script to screenshot a list of websites
GNU Lesser General Public License v3.0
653 stars 162 forks source link

Pass CSS or JS to page to disable notifications #34

Closed clubh closed 4 years ago

clubh commented 4 years ago

Would be nice to be able to pass CSS or JS to the webpage to hide cookie notifications.

maaaaz commented 4 years ago

Do you know if and how it would be possible with the phantomjs renderer ?

maaaaz commented 4 years ago

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.

maaaaz commented 4 years ago

Feature added in v2.94 with the --custom-js option. As a proof, I managed to edit the background color of a page:

nakic commented 3 years ago

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?