diff --git a/apps/browser/src/autofill/services/autofill.service.spec.ts b/apps/browser/src/autofill/services/autofill.service.spec.ts index 19b4135bcf..812891930b 100644 --- a/apps/browser/src/autofill/services/autofill.service.spec.ts +++ b/apps/browser/src/autofill/services/autofill.service.spec.ts @@ -241,6 +241,23 @@ describe("AutofillService", () => { expect(tracker.emissions[0]).toEqual([]); }); + + ["moz-extension://", "chrome-extension://", "safari-web-extension://"].forEach( + (extensionPrefix) => { + it(`returns an empty array when the tab.url starts with ${extensionPrefix}`, async () => { + const tracker = subscribeTo( + autofillService.collectPageDetailsFromTab$({ + ...tab, + url: `${extensionPrefix}/3e42342/popup/index.html`, + }), + ); + + await tracker.pauseUntilReceived(1); + + expect(tracker.emissions[0]).toEqual([]); + }); + }, + ); }); describe("loadAutofillScriptsOnInstall", () => { diff --git a/apps/browser/src/autofill/services/autofill.service.ts b/apps/browser/src/autofill/services/autofill.service.ts index 3580a90f76..eaaf23ca84 100644 --- a/apps/browser/src/autofill/services/autofill.service.ts +++ b/apps/browser/src/autofill/services/autofill.service.ts @@ -130,9 +130,16 @@ export default class AutofillService implements AutofillServiceInterface { pageDetailsFallback$.next([]); }); - // Empty/New tabs do not have a URL. - // In Safari, `tabSendMessage` doesn't throw an error for this case. Fallback to the empty array to handle. - if (!tab.url) { + // Fallback to empty array when: + // - In Safari, `tabSendMessage` doesn't throw an error for this case. + // - When opening the extension directly via the URL, `tabSendMessage` doesn't always respond nor throw an error in FireFox. + // Adding checks for the major 3 browsers here to be safe. + const urlHasBrowserProtocol = [ + "moz-extension://", + "chrome-extension://", + "safari-web-extension://", + ].some((protocol) => tab.url.startsWith(protocol)); + if (!tab.url || urlHasBrowserProtocol) { pageDetailsFallback$.next([]); }