Last active
December 15, 2015 15:02
-
-
Save vurral/84c859858cb4dbfaae15 to your computer and use it in GitHub Desktop.
PhantomJS #13551
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
// Run `python -m SimpleHTTPServer` and `phantomjs --debug=true iframe-error.js` in same folder | |
// Tested with PhantomJS 2.0.1-regression-12506 from https://github.com/skakri/phantomjs/releases/tag/2.0.1-regression-12506 | |
// on OSX 10.11.2 | |
var page = require('webpage').create(); | |
page.open("http://localhost:8000/phantomjs.html", function () { | |
page.evaluate(function () { document.getElementById("open-iframe").click(); }); | |
// We have to wait for the content of the iframe to load | |
setTimeout(function() { | |
page.switchToFrame("demo-iframe"); | |
page.evaluate(function () { document.getElementById("close-iframe").click(); }); | |
// Wait for the async postMessage event | |
setTimeout(function() { | |
page.switchToMainFrame(); // Crashes ~7 out of 10 times | |
phantom.exit(0); | |
}, 70); | |
}, 50); | |
}); |
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
# Run `python -m SimpleHTTPServer` and `python iframe-error.py` in same folder | |
# Tested with PhantomJS 2.0.1-regression-12506 from https://github.com/skakri/phantomjs/releases/tag/2.0.1-regression-12506 | |
# on OSX 10.11.2 | |
from selenium import webdriver | |
driver = webdriver.PhantomJS(service_args=['--debug=true']) | |
driver.get("http://localhost:8000/phantomjs.html") | |
driver.find_element_by_css_selector("#open-iframe").click() | |
driver.switch_to_frame("demo-iframe") | |
driver.find_element_by_css_selector("#close-iframe").click() | |
driver.switch_to.default_content() # Crash |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script> | |
function closeSelf() { | |
parent.window.postMessage("removetheiframe", "*"); | |
} | |
</script> | |
</head> | |
<body> | |
<a href="#" onclick="closeSelf();" id="close-iframe">Close iframe</a> | |
</body> | |
</html> |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script> | |
function createIframe() { | |
ifrm = document.createElement('iframe'); | |
ifrm.setAttribute("src", "/phantomjs-iframe.html"); | |
ifrm.setAttribute("id", "demo-iframe"); | |
ifrm.setAttribute("name", "demo-iframe"); | |
document.body.appendChild(ifrm); | |
} | |
function receiveMessage(event){ | |
if (event.data=="removetheiframe"){ | |
var element = document.getElementById('demo-iframe'); | |
element.parentNode.removeChild(element); | |
} | |
} | |
window.addEventListener("message", receiveMessage, false); | |
</script> | |
</head> | |
<body> | |
<a href="#" onclick="createIframe();" id="open-iframe">Open the iframe</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment