1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

convert thrown error on content script injection block to a warning and early return

This commit is contained in:
Jonathan Prusik
2024-12-23 14:26:17 -05:00
parent 09095b05a9
commit a77d48ddba
2 changed files with 7 additions and 22 deletions

View File

@@ -56,7 +56,6 @@ describe("ScriptInjectorService", () => {
const fakeStateProvider: FakeStateProvider = new FakeStateProvider(accountService);
let configService: MockProxy<ConfigService>;
let domainSettingsService: DomainSettingsService;
const expectedBlockedURIError = new Error("This URI of this tab is on the blocked domains list.");
beforeEach(() => {
jest.spyOn(BrowserApi, "getTab").mockImplementation(async () => tabMock);
@@ -70,6 +69,7 @@ describe("ScriptInjectorService", () => {
platformUtilsService,
logService,
);
jest.spyOn(scriptInjectorService as any, "buildInjectionDetails");
});
describe("inject", () => {
@@ -116,32 +116,14 @@ describe("ScriptInjectorService", () => {
domainSettingsService.blockedInteractionsUris$ = of({ [mockBlockedURI.host]: null });
manifestVersionSpy.mockReturnValue(3);
await expect(
scriptInjectorService.inject({
tabId,
injectDetails: {
file: combinedManifestVersionFile,
frame: 10,
...sharedInjectDetails,
},
}),
).rejects.toThrow(expectedBlockedURIError);
await expect(scriptInjectorService["buildInjectionDetails"]).not.toHaveBeenCalled();
});
it("skips injecting the script in manifest v2 when the tab domain is a blocked domain", async () => {
domainSettingsService.blockedInteractionsUris$ = of({ [mockBlockedURI.host]: null });
manifestVersionSpy.mockReturnValue(2);
await expect(
scriptInjectorService.inject({
tabId,
injectDetails: {
file: combinedManifestVersionFile,
frame: "all_frames",
...sharedInjectDetails,
},
}),
).rejects.toThrow(expectedBlockedURIError);
await expect(scriptInjectorService["buildInjectionDetails"]).not.toHaveBeenCalled();
});
it("injects the script in manifest v2 when given combined injection details", async () => {

View File

@@ -54,7 +54,10 @@ export class BrowserScriptInjectorService extends ScriptInjectorService {
}
if (!injectionAllowedInTab) {
throw new Error("This URI of this tab is on the blocked domains list.");
this.logService.warning(
`${injectDetails.file} was not injected because ${tabURL?.hostname || "the tab URI"} is on the user's blocked domains list.`,
);
return;
}
const injectionDetails = this.buildInjectionDetails(injectDetails, file);