diff --git a/src/plugins/built-in/errorPageKitten/index.test.ts b/src/plugins/built-in/errorPageKitten/index.test.ts
index a677f288..f98ee7af 100644
--- a/src/plugins/built-in/errorPageKitten/index.test.ts
+++ b/src/plugins/built-in/errorPageKitten/index.test.ts
@@ -24,6 +24,8 @@ const REBRANDED_404_BODY = `
Page not found
We can't find the page you're looking for.
+
It may have been moved, deleted or the link might be out of date.
+
Ref: 404
`;
@@ -63,6 +65,23 @@ describe("errorPageKitten", () => {
expect(isSeqta404Page()).toBe(false);
});
+ it("does not detect generic 404 pages on other sites", () => {
+ document.title = "404 - Not Found";
+ document.body.innerHTML = `
+
+
Page not found
+
Sorry, this page does not exist.
+
+ `;
+ expect(isSeqta404Page()).toBe(false);
+ });
+
+ it("does not treat a 404 title alone as SEQTA", () => {
+ document.title = "Error 404";
+ document.body.innerHTML = "Not found
";
+ expect(isSeqta404Page()).toBe(false);
+ });
+
it("plugin run is a no-op outside a 404 page", async () => {
document.title = "SEQTA Learn";
document.body.innerHTML = '';
diff --git a/src/plugins/built-in/errorPageKitten/index.ts b/src/plugins/built-in/errorPageKitten/index.ts
index c99c7021..77ef3250 100644
--- a/src/plugins/built-in/errorPageKitten/index.ts
+++ b/src/plugins/built-in/errorPageKitten/index.ts
@@ -16,12 +16,36 @@ const CARD_HTML = `404 Not Found
SEQTA`;
+function normalizePageText(text: string): string {
+ return text
+ .replace(/[\u2018\u2019]/g, "'")
+ .replace(/\s+/g, " ")
+ .trim();
+}
+
+/** Fingerprints SEQTA's rebranded standalone 404 — not generic site 404s. */
+function isSeqtaRebranded404Message(message: Element): boolean {
+ const heading = message.querySelector("h1");
+ if (normalizePageText(heading?.textContent ?? "").toLowerCase() !== "page not found") {
+ return false;
+ }
+
+ const body = normalizePageText(message.textContent ?? "");
+ return (
+ body.includes("We can't find the page you're looking for") &&
+ body.includes(
+ "It may have been moved, deleted or the link might be out of date.",
+ ) &&
+ body.includes("Ref: 404")
+ );
+}
+
/** Standalone SEQTA 404 document — not the SPA (#container). */
export function isSeqta404Page(): boolean {
if (document.getElementById("container")) return false;
- const heading = document.querySelector(".message > h1");
- const text = heading?.textContent ?? document.title;
- return /not found/i.test(text) || /404/.test(document.title);
+ const message = document.querySelector(".message");
+ if (!message) return false;
+ return isSeqtaRebranded404Message(message);
}
export function mountErrorPageKitten(): () => void {