title: Protractor endurance test memory leak
body: <p>I made a very small test using protractor to open my application (build on angular) and start clicking at random links in a random order. We use this to let the web application run for several days and check for memory leaks.</p>
  
  <p>After some time the memory of the browser (chrome) is huge and when i create a memory dump i find 33k strings all containing the same piece of code (shown below).</p>
  
  <p>I tried searching where this was coming from and it that led me to Webdriver and the code looks like something injected by webdriver to trigger the mouse click ability but from there i'm lost.</p>
  
  <p>Am i doing something wrong or should i clean the memory somewhere in my test?</p>
  
  <p>(When i run the application normally for multiple hours and opening all pages there is no occurrence at all of this string)</p>
  
  <pre><code>"(function() { // Copyright (c) 2012 The Chromium Authors. All rights reserved. 
  // Use of this source code is governed by a BSD-style license that can be 
  // found in the LICENSE file. 
  
  /**
   * Enum for WebDriver status codes.
   * @enum {number}
   */
  var StatusCode = { STALE_ELEMENT_REFERENCE: 10, JAVA_SCRIPT_ERROR: 17, };
  
  /**
   * Enum for node types.
   * @enum {number}
   */
  var NodeType = { ELEMENT: 1, DOCUMENT: 9, };
  
  /**
   * Dictionary key to use for holding an element ID.
   * @const
   * @type {string}
   */
  var ELEMENT_KEY = 'ELEMENT';
  
  /**
   * True if using W3C Element references.
   * @const
   * @type {boolean}
   */
  var w3cEnabled = false;
  
  /**
   * True if shadow dom is enabled.
   * @const
   * @type {boolean}
   */
  var SHADOW_DOM_ENABLED = typeof ShadowRoot === 'function';
  
  /**
   * Generates a unique ID to identify an element.
   * @void
   * @return {string} Randomly generated ID.
   */
  function generateUUID() {
    var array = new Uint8Array(16);
    window.crypto.getRandomValues(array);
    array[6] = 0x40 | (array[6] &amp; 0x0f);"
  
  .... (continues for a lot more lines)
  </code></pre>
  
  <p>The test i try to run is:</p>
  
  <pre><code>import {browser, by, element} from 'protractor';
  
  describe('Webclient', () =&gt; {
    const MAX_SAFE_TIMEOUT = Math.pow(2, 31) - 1;
  
    beforeAll(async function () {
      await browser.get('/');
    });
  
    it('Endurance test', (done) =&gt; {
      runTest();
    }, MAX_SAFE_TIMEOUT);
  });
  
  let counter = 0;
  
  async function runTest() {
  
    try {
      const elements = await element.all(by.css('.header a, .sidebar-left a, .footer a, .content a'));
      let random = Math.floor(Math.random() * elements.length);
  
      while (!(await elements[random].isDisplayed())) {
        random = Math.floor(Math.random() * elements.length);
      }
  
      await elements[random].click();
      console.log('click counter:', counter++, await browser.getCurrentUrl());
    } catch (e) {
      // Do nothing, just continue
    }
  
    // Break the chain so that we don't get one big recursive function
    setTimeout(() =&gt; {
      runTest();
    }, 0);
  }
  </code></pre>