1

While running headless chrome on selenium for python, these two outputs are displayed each time a page is loaded

[0212/153923.202:INFO:CONSOLE(15)] "Cookie banner version 0.11.4-pl4 loaded", source: https://consent.gameforge.com/cookiebanner.js (15)
[0212/153923.205:INFO:CONSOLE(15)] "Initial consent: [object Object]", source: https://consent.gameforge.com/cookiebanner.js (15)

since the python script load many pages, the terminal is filled with dozens of those outputs hence is difficult to read other printed text. Is there a way to prevent those outputs to be displayed in the terminal? For example by filtering out the selenium outputs containing the string 'cookiebanner.js'?

This is a snippet code to reproduce the output

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options = chrome_options, executable_path = ChromeDriverManager().install())
driver.get('https://lobby.ogame.gameforge.com/')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
sound wave
  • 3,191
  • 3
  • 11
  • 29
  • 1
    Does this answer your question? https://stackoverflow.com/a/20748376/12326283 – gmdev Feb 14 '21 at 15:00
  • 1
    @gmdev thank you it works but i guess it blocks other outputs too? i read that `Valid values are from 0 to 3: INFO = 0, WARNING = 1, LOG_ERROR = 2, LOG_FATAL = 3`. The `cookiebanner` messages are blocked with `log-level=1` too, is it better to put `1` or `3` to filter the smallest amount of messages? – sound wave Feb 14 '21 at 15:16
  • I wouldn't want to speak on something I am rather inexperienced in, so I unfortunately can't tell you which one is *better* to use over the others for blocking certain types of messages. Does setting it to `0` filter out the messages or just `1` and `3`? – gmdev Feb 14 '21 at 17:02

1 Answers1

1

While using browsing context to disable the following cookiebanner.js information log messages:

[0215/033952.539:INFO:CONSOLE(15)] "Cookie banner version 0.11.4-pl4 loaded", source: https://consent.gameforge.com/cookiebanner.js (15)
[0215/033952.539:INFO:CONSOLE(15)] "Initial consent: [object Object]", source: https://consent.gameforge.com/cookiebanner.js (15)
[0215/033954.744:INFO:CONSOLE(1)] "Cookie Consent [object Object]", source: https://s3-static.geo.gfsrv.net/browsergamelobby/ogame/3.7.0/js/main.dba2812d.js (1)
[0215/033956.201:INFO:CONSOLE(24)] "Dispatching GFLocaleChange with [object Object]", source: https://gameforge.com/js/connect.js (24)
    

You can add the experimental_option excludeSwitches", ["enable-logging"] as follows:

options = webdriver.ChromeOptions()
options.headless = True
options.add_experimental_option("excludeSwitches", ["enable-logging"])

driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://lobby.ogame.gameforge.com/')

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • thank you! i guess that option does block other outputs too, doesn't it? do you know what's the difference between that option and `chrome_options.add_argument("--log-level=1")` in terms of amount of messages blocked? – sound wave Feb 15 '21 at 00:36
  • @soundwave Atm I'd like to avoid any comment on `add_argument("--log-level=1")`. Though this argument worked earlier but the python clients have changed in the recent times. I need to re-look at the client code before commenting anything. – undetected Selenium Feb 15 '21 at 08:05
  • I'll wait for other answers maybe there is a way to block only output containing a specific keyword (`cookiebanner`) – sound wave Feb 15 '21 at 08:19
  • @soundwave Possibly there is but someone needs to drive deep within the ChromeDriver switches/implementations. – undetected Selenium Jan 18 '23 at 21:11