title: Failed: unknown error: browser is not defined after browser.executeScript() in protractor
body: <p>I have the method where I log in using api from browser console.</p>
  
  <pre><code>    this.logInViaAPI = function (user) {
      browser.executeScript(function (user) {
          var xhr = new XMLHttpRequest();
          xhr.open("POST", '/api/v1/....', true);
          xhr.setRequestHeader('token', browser.params.tokens.token);
          xhr.setRequestHeader('Content-Type', 'application/json');
          xhr.send('{"email": "' + user.login + '", "password": "' + user.apipassword + '"}');
      });
  };
  </code></pre>
  
  <p>and use it in tests </p>
  
  <pre><code>   beforeAll(function () {
      browser.get("");
  });
  
  
  it("test", function (){
      helpers.logInViaAPI(browser.params.regularUser);
      browser.refresh();
  });
  </code></pre>
  
  <p>and I get next error. May be I should do some another things but I have no ideas.</p>
  
  <pre><code>*- Failed: unknown error: browser is not defined
        (Session info: chrome=53.0.2785.143)
        (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64)
              (Session info: chrome=53.0.2785.143)
              (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64)
                at new bot.Error (\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
                at Object.bot.response.checkResponse (\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:109:9)
                at \node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:379:20
                at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
                at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
                at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
                at goog.async.run.processWorkQueue (\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:124:15)
                at process._tickCallback (node.js:368:9)
            From: Task: Run it("test") in control flow
                at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
                at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
                at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
                at goog.async.run.processWorkQueue (\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:124:15)
            From asynchronous test: 
            Error
                at Suite.&lt;anonymous&gt; (\test\e2e\specs\search\search.loggedIn.spec.js:86:5)
                at Object.&lt;anonymous&gt; (\test\e2e\specs\search\search.loggedIn.spec.js:8:1)
                at Module._compile (module.js:435:26)
                at Object.Module._extensions..js (module.js:442:10)
                at Module.load (module.js:356:32)
                at Function.Module._load (module.js:311:12)*
  </code></pre>