Bypass iFrame detection with a Chrome Extension
<p>How can I overwrite the window.top object using a chrome extension?</p>

<p>This is what I'm trying:</p>

<p><strong>manifest.json</strong></p>

<pre><code>{
  "name": "buster",
  "version": "0.0.41",
  "manifest_version": 2,
  "description": "Removes iframe buster scripts",
  "homepage_url": "http://google.com",
  "background": {
    "scripts": ["background.js"]
  },
  "browser_action": {
    "default_title": "buster buster"
  },
  "permissions": [ "webRequest", "webRequestBlocking", "&lt;all_urls&gt;", "tabs"],
  "web_accessible_resources": [
    "index.html"
  ],
  "content_scripts": [
  {
    "matches": ["*://*/*"],
    "run_at": "document_start",
    "js": ["buster.js"],
    "all_frames": true
  }
  ]
}
</code></pre>

<p><strong>background.js</strong></p>

<pre><code>chrome.webRequest.onHeadersReceived.addListener(function (details) {
    return {responseHeaders: details.responseHeaders.filter(function(header) {
        return ((header.name.toLowerCase() !== 'x-frame-options'));
    })};
}, {
    types: ["sub_frame"],
    urls: ["&lt;all_urls&gt;"]
}, ["blocking", "responseHeaders"]);

chrome.browserAction.onClicked.addListener(function (tab) {
    chrome.tabs.update(tab.id, {url: chrome.extension.getURL("index.html")});
});
</code></pre>

<p><strong>buster.js</strong> with all my attempts:</p>

<pre><code>if (top!=self) {
    alert(location.href);
//console.log(document.head.querySelector("script:not([src])").innerHTML)
    window.self=window.top;

    Window.prototype.__defineGetter__('top',function(){return this;});

    window.top = window.top.window;


    var prevent_bust = 0  
    window.onbeforeunload = function() { prevent_bust++ }  
    setInterval(function() {  
      if (prevent_bust &gt; 0) {  
        prevent_bust -= 2  
        window.top.location = 'http://httpstat.us/204'  
      }  
    }, 1) 
}
</code></pre>

<p><strong>index.html</strong> - I'm using stackoverflow.com as an example</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body style="background: #ccc"&gt;
    &lt;iframe id="ifr" src="http://stackoverflow.com/questions/37588058/inject-javascript-at-the-very-top-of-the-page-anti-iframe-buster" width="555" height="555"&gt;&lt;/iframe&gt;
    &lt;!-- http://time.com/4356072/missing-japanese-boy-found-forest/?xid=homepage --&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><a href="https://dl.dropboxusercontent.com/u/18840099/iframeBuster.zip" rel="nofollow">Extension zip file</a></p>