Skip to content

Instantly share code, notes, and snippets.

@Gozala
Forked from anonymous/iframe.js
Created December 11, 2012 21:55
Show Gist options
  • Save Gozala/4262598 to your computer and use it in GitHub Desktop.
Save Gozala/4262598 to your computer and use it in GitHub Desktop.
Updated version
let { Cc, Ci } = require('chrome');
let appShellService = Cc['@mozilla.org/appshell/appShellService;1'].
getService(Ci.nsIAppShellService);
let service = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let window = appShellService.hiddenDOMWindow;
let document = window.document;
let XUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'
let frame = document.createElementNS(XUL, "browser");
frame.setAttribute("type", "content");
frame.setAttribute("src", "data:;charset=utf-8,");
document.documentElement.appendChild(frame);
let docShell = frame.docShell;
docShell.allowAuth = true;
docShell.allowJavascript = true;
docShell.allowPlugins = true;
// New platform capability is required to add window control
// For details see: Bug 635673
if ("allowWindowControl" in docShell)
docShell.allowWindowControl = false;
frame.setAttribute("flex", 1);
frame.setAttribute("transparent", "transparent");
frame.setAttribute("showcaret", true);
frame.setAttribute("clickthrough", "always");
frame.setAttribute("autocompleteenabled", true);
frame.setAttribute("autoscroll", true);
frame.setAttribute("src", "data:text/html,<script>" +
"setTimeout(function(){" +
"window.location='about:blank'" +
"},450);" +
"</script>");
frame.addEventListener("load", function(event) {
console.log("observe destruction of: ", event.target.URL);
let observeID = frame.contentWindow.
QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils).
currentInnerWindowID;
let observer = {
observe: function(subject, topic, data) {
let windowID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
console.log("observe: ", observeID, " window: ", windowID)
if (windowID === observeID) {
console.log("<<<< unload >>>>")
service. removeObserver(observer, "inner-window-destroyed");
}
}
}
service.addObserver(observer, "inner-window-destroyed", false);
}, true)
info: scratch-kit: observe destruction of: data:text/html,<script>setTimeout(function(){window.location='about:blank'},450);</script>
info: scratch-kit: observe destruction of: about:blank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment