From dfcfe7a3c675b11b76daadf02d9eba2d85393f5a Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Mon, 21 Sep 2026 11:47:44 -0400 Subject: [PATCH] Do not read document in getSiteName when there is none getSiteName reads document.location.search so the popup can pass a title and url. background.ts also calls it from the MV3 service worker, which has no document, so the autofill command threw ReferenceError after the content script and css had already been injected and no code was ever sent to the tab. Signed-off-by: Arpit Jain --- src/utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 508f06503..ef91309db 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,10 @@ export async function getSiteName() { const tab = await getCurrentTab(); - const query = new URLSearchParams(document.location.search.substring(1)); + // The popup passes the tab's title and url in its own query string. The MV3 + // service worker calls this too and has no document, so fall back to the tab. + const query = new URLSearchParams( + typeof document !== "undefined" ? document.location.search.substring(1) : "" + ); let title: string | null; let url: string | null;