title: Is it possible to execute_script with Ruby's selenium-webdriver while page starts to load
body: <p>I am trying to make javascript execute while loading</p>
  
  <p>I am trying to achieve an effect that can be achieved if script would make following change</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      window.screen.__defineGetter__('width', function(){return 1024;});
      window.screen.__defineGetter__('height', function(){return 768;});
  &lt;/script&gt;
  </code></pre>
  
  <p>However, I cannot put this javascript inside a page, they have to be coming from Ruby, there are other things I might add other than <code>window.width</code> and <code>window.screen</code></p>
  
  <pre><code>driver = Selenium::WebDriver.for :firefox, :profile =&gt; profile
  driver.execute_script("window.screen.__defineGetter__('height', function(){return 768;});") # this executes before page load starts
  driver.navigate.to 'http://somesite.com/'
  driver.execute_script("window.screen.__defineGetter__('height', function(){return 768;});") # this executes after page completely loads
  </code></pre>
  
  <p>So, what I want to do is to execute for example</p>
  
  <p><code>driver.execute_script("window.screen.__defineGetter__('height', function(){return 768;});")</code>     </p>
  
  <p>this while page loads, it does not work if I put this before <code>navigate.to</code> or after <code>navigate.to</code>. The same is if I change <code>.navigate.to</code> with <code>.get</code></p>