dgtlmoon / changedetection.io

The best and simplest free open source web page change detection, website watcher, restock monitor and notification service. Restock Monitor, change detection. Designed for simplicity - Simply monitor which websites had a text change for free. Free Open source web page change detection, Website defacement monitoring, Price change notification
https://changedetection.io
Apache License 2.0
17.33k stars 965 forks source link

[feature] Start chromedriver in headless mode #529

Closed blap closed 2 years ago

blap commented 2 years ago

Version and OS All

Is your feature request related to a problem? Please describe. Using chromedriver always open a new instance of google chrome. Not always needed.

Describe the solution you'd like We can start chromedriver in headless mode. Headless execution is getting popular now−a−days since the resource consumption is less and execution is done at a faster speed. Post version 59, Chrome supports headless execution. ChromeOptions class is utilized to modify the default characteristics of the browser. The addArguments method of the ChromeOptions class is used for headless execution and headless is passed as a parameter to that method. https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md

Describe the use-case and give concrete real-world examples Headless Chrome allows running Chrome in a headless/server environment. Expected use cases include loading web pages, extracting metadata (e.g., the DOM) and generating bitmaps from page contents -- using all the modern web platform features provided by Chrome.

Additional context What is a headless browser? How do you run Headless Chrome? https://www.youtube.com/watch?v=4gdQg-ikEkw

dgtlmoon commented 2 years ago

Not needed, we run it in a container and you never see it anyway, unless you mean for Windows, so in this case, please update the wiki https://github.com/dgtlmoon/changedetection.io/wiki/Fetching-pages-with-WebDriver#microsoft-windows---running-chromedriver-natively-without-docker

blap commented 2 years ago

Not needed, we run it in a container and you never see it anyway, unless you mean for Windows, so in this case, please update the wiki https://github.com/dgtlmoon/changedetection.io/wiki/Fetching-pages-with-WebDriver#microsoft-windows---running-chromedriver-natively-without-docker

Yes, in Windows. But the headless function works when you call chrome in your code, like this example:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://google.com")
dgtlmoon commented 2 years ago

But you wrote "Version and OS: All" in your report, now you say Windows ?

ah ok, so maybe --headless should be set by default, now I understand, its good for linux (doesnt hurt anything) and makes better sense in windows, right?

blap commented 2 years ago

But you wrote "Version and OS: All" in your report, now you say Windows ?

ah ok, so maybe --headless should be set by default, now I understand, its good for linux (doesnt hurt anything) and makes better sense in windows, right?

Yes. Thank you! And save some CPU too in linux.

dgtlmoon commented 2 years ago

I just switched our paid installations to use headless mod, and it's made zero difference to the CPU load

pokegamer5547 commented 9 months ago

I just switched our paid installations to use headless mod, and it's made zero difference to the CPU load

There are some cases where it's still helpful to have it like a environment without gui. I use changedetection and chromedriver(via binary) on termux and i wish i dont have to run a x server just to use chromedriver when headless exist. Can you please add an option atleast for users who wanr it? Or tell us which code allows it to change so i could make my private fork version with that changes for my use case.

gety9 commented 1 week ago

@pokegamer5547

pokergamer hi, i am also on android / termux.

Could you please explain how to set-up the chromedriver(via binary) on termux? (so i can use CD.io to test javascript websites)

Also is it possible to set-up CD.io + playright android? (https://playwright.dev/docs/api/class-android) Or is your way better?

pokegamer5547 commented 1 week ago

@pokegamer5547

* "I use changedetection and chromedriver(via binary) on termux"

pokergamer hi, i am also on android / termux.

Could you please explain how to set-up the chromedriver(via binary) on termux? (so i can use CD.io to test javascript websites)

Also is it possible to set-up CD.io + playright android? (https://playwright.dev/docs/api/class-android) Or is your way better?

@gety9 My current method is a bit hacky tbh but i'll type it here.

First setup termux x11 (install it's apk and it's package in termux)

Set following variable export XDG_RUNTIME_DIR=${TMPDIR}

install proot distro debian and launch it with /data/data/com.termux/files/usr/bin/login termux-x11 :0 >/dev/null & proot-distro login debian --isolated --shared-tmp 2>&1

install chromium and chromedriver in that debian distro. Set these two vars in proot distro export XDG_RUNTIME_DIR=${TMPDIR} export DISPLAY=:0 Open file /etc/chromium.d/default-flags Add following line to that file. CHROMIUM_FLAGS="CHROMIUM_FLAGS --no-sandbox

Test whether running chromium is displaying the browser in termux-x11.

If it works then, run chromedriver, set varialble (where changedetection is installed, whether in proot distro or in termux WEBDRIVER_URL="http://localhost:41529 (replace port no with chromedriver port no of yours)

Now run changedetection.io again and configure it.

Lemme know if you have any problems.

gety9 commented 6 days ago

@pokegamer5547

thank for your reply, it pointed me out in right direction.

the chromium part can be done easier now:

pkg install tur-repo
pkg install chromium
chromedriver

that's it, chromedriver is running @ 127.0.0.1:9515

pokegamer5547 commented 6 days ago

@pokegamer5547

thank for your reply, it pointed me out in right direction.

the chromium part can be done easier now:

pkg install tur-repo
pkg install chromium
chromedriver

that's it, chromedriver is running @ 127.0.0.1:9515

@gety9 true. But i noticed tur chromium is often behind in updates and i was bit concerned about security so yeah. But i'm glad i was helpful to you :)

gety9 commented 1 day ago

@pokegamer5547 did you manage to make it work headless?

as i understand we should be able to add headless tag to

CHROMIUM_FLAGS="CHROMIUM_FLAGS --no-sandbox

?

pokegamer5547 commented 1 day ago

@pokegamer5547 did you manage to make it work headless?

as i understand we should be able to add headless tag to

CHROMIUM_FLAGS="CHROMIUM_FLAGS --no-sandbox

?

@gety9 I did tried using some flags like --headless or headless=new but for some reason it's showing error in cdio. That's why i commented on this issue wishing to see native support for headless mode by default.