Skip to content

Commit

Permalink
send postMessage on 404 page (#180)
Browse files Browse the repository at this point in the history
Send a new 'archive-not-found' message (via postMessage) to parent frame from top-level archive 404 page to better notify embedder of when a 404 page is loaded (part of webrecorder/replayweb.page#333).
  • Loading branch information
ikreymer authored Jun 18, 2024
1 parent 4113e8f commit 977cc50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/sw.js

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,31 @@ class Collection {

const msg =`
<html>
<head>
<script>
window.requestURL = "${requestURL}";
</script>
</head>
<body style="font-family: sans-serif">
<h2>Archived Page Not Found</h2>
<p>Sorry, this page was not found in this archive:</p>
<p><code id="url" style="word-break: break-all; font-size: larger"></code></p>
${this.liveRedirectOnNotFound && request.mode === "navigate" ? `
<p>Redirecting to live page now... (If this URL is a file download, the download should have started).</p>
<script>
window.top.location.href = "${requestURL}";
window.top.location.href = window.requestURL;
</script>
` : `
`}
<p id="goback" style="display: none"><a href="#" onclick="window.history.back()">Go Back</a> to the previous page.</a></p>
<p>
<a target="_blank" href="${requestURL}">Load the live page</a> in a new tab (or download the file, if this URL points to a file).
<a id="livelink" target="_blank" href="">Load the live page</a> in a new tab (or download the file, if this URL points to a file).
</p>
<script>
document.querySelector("#url").innerText = "${requestURL}";
document.querySelector("#url").innerText = window.requestURL;
document.querySelector("#livelink").href = window.requestURL;
let isTop = true;
try {
if (window.parent._WB_wombat_location) {
Expand All @@ -149,11 +155,17 @@ class Collection {
}
if (isTop) {
document.querySelector("#goback").style.display = "";
window.parent.postMessage({
wb_type: "archive-not-found",
url: window.requestURL,
ts: "${requestTS}"
}, "*");
}
</script>
</body>
</html>
`;
`;
return notFound(request, msg);
} else if (response instanceof Response) {
// custom Response, not an ArchiveResponse, just return
Expand Down

0 comments on commit 977cc50

Please sign in to comment.