Selenium Chrome driver headless mode not working
G

1

5

My code worked perfectly until yesterday when I updated Google Chrome to version 110.0.5481.77. Now it's not working in headless mode:

options.add_argument("--headless")

I even tried adding options.add_argument("--window-size=1280,700") but still not working. Although if I remove the headless option it again works correctly!

Gastro answered 9/2, 2023 at 16:10 Comment(1)
G
19

Accroding to this answer and Google Chrome release notes you should add the headless mode option like below:

options.add_argument("--headless=new")

and no need to specify the window size

Gastro answered 9/2, 2023 at 16:21 Comment(9)
But it seems by default uses a small resolution. It seems to be something like 800x600.Borgeson
@PauloOliveira My use case is well served by the default, but I think you can use the options.add_argument("--window-size=1280,700") to justify that. If that doesn't solve feel free to provide a more accurate answer.Gastro
Does not work for me on 112 stable or 113 beta.Borgeson
@PauloOliveira I've got no idea, if you could figure it out post an answer.Gastro
This works with Chrome 114 and Chromium 114. Nothing else worked for me. Strange thing is, that for other sites I can use the options.add_argument("--headless") version, but for one specific site I can'tHangdog
Do you know why it's now working for Kayak? #78094100Teahan
@ErikJohnsson unfortunately I'm not aware of the inner workings nor the specific site you are scraping, but I guess seeing the Selenium logs may help you identify the problem. It's easy to set that up, I can't say off the top of my head, but with a quick search you can do that.Gastro
It works today as well.. thanks for the answer @MaskedMan.Cairngorm
@SwaroopHumane glad it helped, happy coding.Gastro

© 2022 - 2024 — McMap. All rights reserved.