Created
June 15, 2013 03:49
-
-
Save justin-c-rounds/5786812 to your computer and use it in GitHub Desktop.
Attempting to use zombie in node.js to load content into a dynamically created iframe. Doesn't seem to work. I am new to node.js — what am I doing wrong?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
browser = require('zombie'); | |
browser = new browser(); | |
browser.visit('https://dl.dropboxusercontent.com/u/625330/iframe/index.html') | |
document = browser.document; | |
iframe = document.createElement('iframe'); | |
document.body.appendChild(iframe) | |
iframe.onload = function () { | |
console.log('loaded') // this does not happen | |
}; | |
iframe.src = 'https://dl.dropboxusercontent.com/u/625330/iframe/frame.html'; | |
// Trying the above commands in node I get: | |
// iframe.location.href --> 'https://dl.dropboxusercontent.com/u/625330/iframe/frame.html' | |
// iframe.contentDocument.readyState --> 'loading' | |
// iframe.contentDocument.body --> null | |
// Seems like it never loads | |
//I put some console.log calls in the compiled zombie code (in dom_iframe.js): | |
HTML.HTMLFrameElement.prototype._attrModified = function(name, value, oldValue) { | |
var onload, url, | |
_this = this; | |
HTML.HTMLElement.prototype._attrModified.call(this, name, value, oldValue); | |
if (name === "name") { | |
return this.ownerDocument.parentWindow.__defineGetter__(value, function() { | |
return _this.contentWindow; | |
}); | |
} else if (name === "src" && value) { | |
console.log('HEY THERE') // I see this | |
url = HTML.resourceLoader.resolve(this.ownerDocument, value); | |
this.contentWindow.location = url; | |
onload = function() { | |
console.log('I AM LOADED') // I never see this | |
_this.contentWindow.removeEventListener("load", onload); | |
onload = _this.ownerDocument.createEvent("HTMLEvents"); | |
onload.initEvent("load", true, false); | |
return _this.dispatchEvent(onload); | |
}; | |
return this.contentWindow.addEventListener("load", onload); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh dear, I've been working too much. Of course the while loop is blocking everything. Also the iframe content page is "frame.html" not "iframe.html". Alright, so now if I do:
I get:
But the onload doesn't fire. Using addEventListener('load'... also doesn't work.