Which headless browsers can handle popups effectively?

I have experimented with a couple of Docker images, one being PhantomJS and the other a standalone Chrome setup, and found that neither seems to support JavaScript popups initiated through window.open. I only ever see one element in driver.window_handles. I’m considering trying this without Docker, but any insights or related information would be greatly appreciated. I’m working with Python and Selenium WebDriver for my project.

If you're facing issues with handling popups using headless browsers, there are a few solutions that might help you achieve better results more effectively:

1. **Switch to Headless Chrome or Firefox:** Both Chrome and Firefox offer robust support for JavaScript popups when run in headless mode. They're known for maintaining compatibility with web standards and can handle popups using Selenium WebDriver with minimal setup.

Here's an example using Python and Selenium with Chrome:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True

# Initialize Chrome driver
driver = webdriver.Chrome(options=options)

# Open a new window
main_window = driver.current_window_handle
driver.execute_script("window.open('http://example.com');")

# Switch to new window handle
driver.switch_to.window(driver.window_handles[-1])
print("New window title:", driver.title)

2. **Check for browser compatibility issues:** Ensure the headless browser version you are using is up-to-date. Compatibility between Selenium and the browser driver is crucial to handling popups efficiently.

Using these steps, you should be able to handle JavaScript popups effectively in a headless environment, optimizing your workflow without running into Docker-specific issues.