title: How to restore native browser object without creating iframe?
body: <p>I make an embedded JS code which works on thousands of different sites. I definitely want to use some standard browser features (like <code>window.JSON.stringify</code>), but sometimes it simply doesn't work, because a site has some code that ran before mine and replaced native object with something incompatible with my expectations (and standards of course).</p>
  
  <p>Unfortunately the way of restoring native functions by deleting them (<code>delete JSON.stringify</code>) doesn't work in this case because I need to restore a whole object, not only its method. I've heard about a handy way to restore native object, which is iframe creation for getting a new window instance:</p>
  
  <pre><code>function getNativeJSON() {
    if (!window.JSON || !/native code/.test(window.JSON.stringify.toString()) {
        var iframe = document.createElement('iframe');
        document.documentElement.appendChild(iframe);
        return iframe.contentWindow.JSON;
    }
  
    return window.JSON;
  }
  </code></pre>
  
  <p>This approach works fine for me, but sometimes (very rarely, about 1 of 10000 executions) fails. I guess this can be a consequence of some weird behavior like iframe that isn't loaded yet or anything else. Thus this method is neither elegant enough (or I just don't like it), nor can be easily reproduced and debugged.</p>
  
  <p>Maybe do you know any way to restore native browser objects, like <code>JSON</code>?</p>
  
  <p><strong>UPDATE:</strong> Of course the iframe I use is appended to DOM before.</p>