innocent98
innocent98

Reputation: 13

How to use selenium with proxy auth in headless mode?

I'd like to use headless mode with proxy auth login:pass in my python script. I use chrome here.

I have tried creating extension and adding it to chrome, but it works only without headless mode. I was looking for similar issues, but there's no solution like it was unsupoorted. Can anybody give me any tips?

Upvotes: 0

Views: 638

Answers (2)

woffelski
woffelski

Reputation: 1

To add to that, you probably want to use Manifest V3 in your extension. I had used Manifest V2 in mine and it was causing issues with newer Chrome versions. Essentially, the extension would not get loaded properly and would cause a timeout error when trying to load generated background page.html.

To add to that, it was working fine in my development environment, which was running on an older Chrome version than production (not ideal, I know). Needless to say, that it took me a while to figure out the root cause.

With Manifest V3 and the options.add_argument("--headless=new") setting mentioned previously, my extension for proxy authentication is now running absolutely fine in Selenium with headless Chrome.

Upvotes: 0

Michael Mintz
Michael Mintz

Reputation: 15556

Regular headless mode doesn't support extensions, however, Chrome added a newer headless mode that does. Here's how to set it with Selenium options:

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

More info: https://github.com/chromium/chromium/commit/e9c516118e2e1923757ecb13e6d9fff36775d1f4

This assumes you are already using https://stackoverflow.com/a/35293284/7058266 for creating a Chrome extension to set proxy with auth. You may want to see how to set proxy with authentication in selenium chromedriver python? for other ways of setting a proxy.

Upvotes: 0

Related Questions