title: Selenium + Headless Chrome + JS
body: <p>I am using <code>2.33</code> chrome driver and trying to access variable defined in HTML as <code>&lt;script&gt;var foo = "bar";&lt;/script&gt;</code> as follows: </p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  chrome_options = Options()
  #chrome_options.add_argument("--headless")
  chrome_options.add_argument("--disable-gpu")
  chrome_options.add_argument("--window-size=1920x1080")
  chrome_options.add_argument("--enable-javascript")
  driver_path = '&lt;path&gt;'
  driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_path)
  driver.get("&lt;url&gt;")
  driver.execute_script("return window.foo")
  </code></pre>
  
  <p>and it works fine. However, if uncomment <code>chrome_options.add_argument("--headless")</code>, then, it returns <code>None</code> (and if I try to return <code>$</code> it throws <code>unknown error: $ is not defined</code>).</p>
  
  <p>Why using headless mode influences the results in a such a way?</p>