mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-02 13:23:29 +01:00
[PM-15065] Extension not loading when accessed via URL (#12160)
* add check for extension prefixes in the three major browsers. - Firefox does not throw an error or receive the message. Adding checks for Safari and Chrome for safety if this functionality were to change. * remove unneeded mock rejection * move prefixes to dedicated array * refactor protocol check to its own variable
This commit is contained in:
parent
a95eaeb6f5
commit
1229d25fec
@ -241,6 +241,23 @@ describe("AutofillService", () => {
|
|||||||
|
|
||||||
expect(tracker.emissions[0]).toEqual([]);
|
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", () => {
|
describe("loadAutofillScriptsOnInstall", () => {
|
||||||
|
@ -130,9 +130,16 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
pageDetailsFallback$.next([]);
|
pageDetailsFallback$.next([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Empty/New tabs do not have a URL.
|
// Fallback to empty array when:
|
||||||
// In Safari, `tabSendMessage` doesn't throw an error for this case. Fallback to the empty array to handle.
|
// - In Safari, `tabSendMessage` doesn't throw an error for this case.
|
||||||
if (!tab.url) {
|
// - 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([]);
|
pageDetailsFallback$.next([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user