title: How do I catch object creation using a proxy?
body: <p>Thank you for taking the time to read my problem. A website's javascript I'm reverse engineering executes the following line:</p>
  <pre><code>this.socket = new WebSocket(o.host)
  </code></pre>
  <p>The line is buried in functions of other functions, etc. so I am not able to access it normally during runtime. I would like to use a Proxy object to &quot;inject&quot; code whenever new Websocket() is called in order to notify me of its creation and save it to a global variable I would prepare prior.</p>
  <p>My greasemonkey script would look something like this:</p>
  <pre><code>var caught_socket; // prepare variable
  
  handler = {
    apply: function(target, thisArg, argumentsList) {
      console.log(&quot;WebSocket was created!&quot;);
      caught_socket = target;
    }
  }
  
  WebSocket = new Proxy(WebSocket, handler);
  </code></pre>
  <p>This obviously does not work and I would be grateful for any help or demonstration of how Proxies actually work!</p>