Skip to content

Do not read document in getSiteName when there is none - #1592

Open
arpitjain099 wants to merge 1 commit into
Authenticator-Extension:devfrom
arpitjain099:fix/sitename-in-service-worker
Open

arpitjain099 wants to merge 1 commit into
Authenticator-Extension:devfrom
arpitjain099:fix/sitename-in-service-worker

Conversation

@arpitjain099

Copy link
Copy Markdown

getSiteName reads document.location.search so the popup can pass a title and url through its own query string. background.ts also calls it, from the chrome.commands.onCommand("autofill") handler, and on Chrome and Edge that is an MV3 service worker with no document.

Driving the transpiled function with a stubbed getCurrentTab:

service worker (no document) -> threw: ReferenceError: document is not defined
page (document present)      -> ["examplesite","example","example.com"]

By the time it throws, scripting.executeScript and insertCSS have already run, so the content script and its css are injected into the page and then nothing is sent to it. The shortcut looks like it does nothing. The Firefox manifest uses a background script rather than a worker, which is why that build is unaffected.

The query string is only ever populated for the popup, so the fix reads it when a document exists and falls back to the tab otherwise, which is the branch already there for when the query is empty. After the change both contexts return the same triple. webpack compiles clean.

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 <arpitjain099@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant