forked from bluesmoon/boomerang
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround for document.write changing readyState after onload
- Loading branch information
1 parent
9f1f513
commit 2822a79
Showing
3 changed files
with
89 additions
and
18 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<!--[if IE 8]> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN" "http://www.w3.org/TR/html1/DTD/html1-transitional.dtd"> | ||
<![endif]--> | ||
|
||
<!-- | ||
When document.write is used to replace the contents of the page and inject boomerang, the document readyState | ||
will go from "complete" back to "loading" and then to "complete" again. The second transition to "complete" | ||
doesn't fire a second pageshow event in some browsers (e.g. Safari). Boomerang needs to check if performance.timing.loadEventStart has occurred | ||
to detect this scenario. | ||
--> | ||
<html> | ||
<head> | ||
</head> | ||
<body onload="setTimeout(onLoad, 100);"> | ||
|
||
<!-- the textarea contains the html that we'll use with document.write to replace the page --> | ||
<textarea id="newdocument"> | ||
<%= header %> | ||
<script src="122358-document-write.js" type="text/javascript"></script> | ||
<%= boomerangSnippet %> | ||
<script> | ||
BOOMR_test.init({ | ||
testAfterOnBeacon: 1, | ||
onBoomerangLoaded: function() { | ||
setTimeout(function() { | ||
document.close(); | ||
// readyState will return to "complete" without firing a second pageshow event in Safari | ||
}, 100); | ||
} | ||
}); | ||
</script> | ||
<div id="content"></div> | ||
<%= footer %> | ||
</textarea> | ||
|
||
<script> | ||
function onLoad() { | ||
// replace our page | ||
var newdocument = document.getElementById("newdocument").value; | ||
document.open(); | ||
document.write(newdocument); | ||
// wait until boomerang has loaded before closing the document so that it detects a "loading" readyState | ||
} | ||
</script> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*eslint-env mocha*/ | ||
/*global assert*/ | ||
|
||
describe("e2e/06-bugs/122358-document-write", function() { | ||
var tf = BOOMR.plugins.TestFramework; | ||
var t = BOOMR_test; | ||
|
||
it("Should have sent a beacon", function(done) { | ||
t.ensureBeaconCount(done, 1); | ||
}); | ||
}); |