title: Log all arguments to RegExp or //
body: <p>For debugging (using puppeteer/headless Chrome), I want to log all regular expression patterns of a page (eg, all arguments to <code>new RegExp()</code>, <code>//</code>). I could replace <code>window.RegExp</code> with my own function, but that won't catch <code>/pattern/</code> regexes. How to proceed?</p>
  
  <p><strong>Update</strong>: the awesome answer, thanks to @vlaz, is this:</p>
  
  <pre><code>var regex = /abc/;
  
  origtest = RegExp.prototype.test;
  RegExp.prototype.test = function (p, f) {
      process.stdout.write(this + "\n");
      return origtest.apply(this, arguments);
  };
  
  console.log(regex.test("bla"));
  </code></pre>
  
  <p>Can't use console.log in the replacement function, because console.log itself uses RegExp.</p>