How to Make Chrome Headless After I Login Manually

How can I switch from headless mode to normal mode using Google Chrome and Selenium?

No, it won't be possible to open google-chrome in headless mode and moving forward shift to the headed mode.



Deep Dive

When you configure an instance of a ChromeDriver using ChromeOptions(), in the process of initiating a new Chrome Browsing Session the configuration gets baked into the chromedriver executable and will persist till the lifetime of the WebDriver and being uneditable. So you can't add any further ChromeOptions to the WebDriver instance which is currently in execution.

Even if you are able to extract the ChromeDriver and ChromeSession attributes e.g. Session ID, Cookies, UserAgent and other session attributes from the already initiated ChromeDriver and Chrome Browsing Session still you won't be able to change the set of attributes of the ChromeDriver.

A cleaner way would be to call driver.quit() within tearDown(){} method to close and destroy the current ChromeDriver and Chrome Browser instances gracefully and then span a new set of ChromeDriver and Chrome Browser instance with the new set of configurations.



tl; dr

You can find a couple of relevant discussions in:

  • How to set selenium webdriver from headless mode to normal mode within the same session?
  • Change ChromeOptions in an existing webdriver

How to set selenium webdriver from headless mode to normal mode within the same session?

No, it won't be possible to make Chrome operate initially in headless mode and then switch back to normal mode within the same session.

When you configure an instance of a ChromeDriver with ChromeOptions() to span a new Chrome Browsing Context the configuration gets baked within the chromedriver executable which will persist for the lifetime of the WebDriver and being uneditable. So you can't modify/add any existing/new configuration through ChromeOptions() class to the WebDriver instance which is currently in execution.

Even if you are able to extract the ChromeDriver and ChromeSession attributes e.g. Session ID, Cookies, UserAgent and other session attributes from the already initiated ChromeDriver and Chrome Browsing Session still you won't be able to change the set of attributes of the ChromeDriver.

A cleaner way would be to call driver.quit() within tearDown(){} method to close and destroy the current ChromeDriver and Chrome Browser instances gracefully and then span a new set of ChromeDriver and Chrome Browser instance with the new set of configurations.


tl; dr

You can find a couple of relevant discussions in:

  • Change ChromeOptions in an existing webdriver
  • How do I make Chrome Headless after I login manually

Selenium: Disable headless when code is running? (Python)

No, it won't be possible to initialize google-chrome headlessly and then make it visible to solve the captcha.

When you configure ChromeDriver using ChromeOptions() to initiate headless in the process of initiating a new Chrome Browsing Session the configuration gets baked into the chromedriver executable and will persist till the lifetime of the WebDriver and remains uneditable. So you modify the ChromeOptions of the WebDriver instance which is currently in execution.

Even if you are able to extract the ChromeDriver and ChromeSession attributes e.g. Session ID, Cookies and other session attributes from the already initiated ChromeDriver and Chrome Browsing Session still you won't be able to change the set of attributes of the ChromeDriver.

A cleaner way would be to call driver.quit() within tearDown(){} method to close and destroy the current ChromeDriver and Chrome Browser instances gracefully and then span a new set of ChromeDriver and Chrome Browser instance with the new set of configurations.



References

You can find a couple of relevant discussions in:

  • How to set selenium webdriver from headless mode to normal mode within the same session?
  • Change ChromeOptions in an existing webdriver
  • How do I make Chrome Headless after I login manually


Related Topics



Leave a reply



Submit