Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass CSS or JS to page to disable notifications #34

Closed
clubh opened this issue Nov 7, 2019 · 4 comments
Closed

Pass CSS or JS to page to disable notifications #34

clubh opened this issue Nov 7, 2019 · 4 comments

Comments

@clubh
Copy link

clubh commented Nov 7, 2019

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

@maaaaz
Copy link
Owner

maaaaz commented Nov 26, 2019

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

@maaaaz
Copy link
Owner

maaaaz commented Jun 21, 2020

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
Copy link
Owner

maaaaz commented Aug 23, 2020

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
    https_archive apache org_443_dist_tomcat_

@nakic
Copy link

nakic commented Jun 4, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants