title: Passing WebDriver's Browser instance to JavaScript in Appium
body: <p>I am testing an Android Phone application which is based on Hybrid Application Canvas, most of the functionalities i have to test are Canvas based and only way i have is to use JavaScript to be called from Python Scripts.</p>
  
  <p>Before executing Javascript, I convert Phones Native View to Web View by using set Contexts</p>
  
  <pre><code>def set_current_context(self, num_ctx):
          self.driver.switch_to.context(self.driver.contexts[int(num_ctx)])
  
  def set_serial(self, android_serial):
          desired_caps = self.getDevice(android_serial)
          self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
          return self.driver
  </code></pre>
  
  <p>Basic JavaScripts like "document.title" or "window.xyz" works fine and performs certain action.</p>
  
  <p>Now; If i want to fetch page information (Which previously was done using nightwatch) </p>
  
  <pre><code>this.browser.page.YourPage(); // Nightwatch javascript
  </code></pre>
  
  <p>but if i directly send above command i get error <code>JavascriptException: Message: javascript error: Cannot read property 'page' of undefined</code></p>
  
  <pre><code>def direct_script(self, script, *args):
          print(script, *args)
          self.driver.execute_script("$(document).ready (function (){ this.browser.page.YourPage() });", *args)
  </code></pre>
  
  <p>Manually i checked from console of the browser where <code>this.browser</code> returned <code>undefined</code>.</p>
  
  <p>So in my opinion i think there should be some way to pass browser instance on which i can run commands.</p>