title: Why aren't my polyfills being loaded properly in webdriver Firefox?
body: <p>I have this polyfill in JS for my site:</p>
  <pre><code>if (!Date.prototype.toSQLDate) {   
      console.log('Adding my custom polyfill');                                                                                                                                                                                                       
      Date.prototype.toSQLDate = function () {                                                                                                                                                                                 
          // relevant code snipped, but assume:
          // return some string like '2000-01-01';
      }                                                                                                                                                                                                                                         
  }
  </code></pre>
  <p>When I load the website manually, I see the console log and I can do:</p>
  <pre><code>var x = new Date(2000, 0, 1);
  console.log(x.toSQLDate()) =&gt; '2000-01-01'
  </code></pre>
  <p>This works both in Chrome/Chromium(96) and Firefox(95+)</p>
  <p>However, when I run my automated tests against this website, in Firefox(95) only (Chrome works fine) I get this when attempting to run the same code via webdriver.execute_script</p>
  <pre><code>from selenium import webdriver
  wd = webdriver.Firefox()
  wd.get(...myurl)
  wd.execute_script('var x = new Date(2000, 0, 1); return x.toSQLDate()')
  &gt;&gt;&gt;&gt;
  selenium.common.exceptions.JavascriptException: Message: TypeError: x.toSQLDate is not a function
  </code></pre>
  <p>What? If I watch the automated test with the console open, I can see my console.log telling me that it successfully added the polyfill. I can interact with the browser in the console and do the exact same logic and get a valid string back. But when webdriver executes it, it's not in the same js context? And only in Firefox.</p>
  <p>This behavior is present in both Python2.7/selenium3 and Python3.8/selenium4</p>
  <p>What is going on here? Do I need to enable some sort of sandbox js escape in Firefox?</p>
  <p><strong>Additional Information:</strong></p>
  <p>It appears that there may be some &quot;quirk&quot; in the way firefox/geckodriver treats globals. Consider this simple script:</p>
  <pre><code>from selenium import webdriver
  ff = webdriver.Firefox()
  ff.get('http://www.google.com')
  ff.execute_script('return Date === window.Date') =&gt; False
  ff.execute_script('console.log(Date === window.Date)') =&gt; false
  
  # But this same script shows true for chrome.
  </code></pre>