Skip to content

Commit

Permalink
404 improvements: send a new 'error-not-found' message to parent wind…
Browse files Browse the repository at this point in the history
…ow when 404 page is loaded, to make it easier to detect 404s

in RWP embeds (part of webrecorder/replayweb.page#333)
  • Loading branch information
ikreymer committed Jun 18, 2024
1 parent 95e4faf commit 90129cc
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 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,16 @@ class Collection {
}
if (isTop) {
document.querySelector("#goback").style.display = "";
window.parent.postMessage({
url: window.requestURL,
wb_type: "error-not-found",
});
}
</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 90129cc

Please sign in to comment.