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:
@@ -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 () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user