Skip to content

Instantly share code, notes, and snippets.

@johnboxall
Created April 10, 2013 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnboxall/5355380 to your computer and use it in GitHub Desktop.
Save johnboxall/5355380 to your computer and use it in GitHub Desktop.
<html>
<head>
<script>
/**
* In 1s, `onError` will be called to 'recover' the original document.
*/
onError = function() {
var s;
while (s = document.scripts[0]) s.parentNode.removeChild(s);
var openingHTMLTag = openingTag(document.documentElement);
var headEl = $$('head')[0];
var openingHeadTag = openingTag(head);
var headInnerHTMLandClosingTag = head.innerHTML;
var bodyOuterHTML = $$('plaintext')[0].innerText;
document.open();
document.write(openingHTMLTag, openingHeadTag, headInnerHTMLandClosingTag, bodyOuterHTML);
document.close();
}
function openingTag(el) {
var tagName = el.tagName;
return el.cloneNode(false).outerHTML.replace(RegExp('</' + tagName + '>$','i'), '\n');
}
function $$(tag) {
return document.getElementsByTagName(tag);
}
setTimeout(onError, 1000);
</script>
<title>Capturing Recovery Test</title>
<plaintext>
</head>
<body>
<h1>Capturing Recovery Test</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment