mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33: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);
|
const fakeStateProvider: FakeStateProvider = new FakeStateProvider(accountService);
|
||||||
let configService: MockProxy<ConfigService>;
|
let configService: MockProxy<ConfigService>;
|
||||||
let domainSettingsService: DomainSettingsService;
|
let domainSettingsService: DomainSettingsService;
|
||||||
const expectedBlockedURIError = new Error("This URI of this tab is on the blocked domains list.");
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn(BrowserApi, "getTab").mockImplementation(async () => tabMock);
|
jest.spyOn(BrowserApi, "getTab").mockImplementation(async () => tabMock);
|
||||||
@@ -70,6 +69,7 @@ describe("ScriptInjectorService", () => {
|
|||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
logService,
|
logService,
|
||||||
);
|
);
|
||||||
|
jest.spyOn(scriptInjectorService as any, "buildInjectionDetails");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("inject", () => {
|
describe("inject", () => {
|
||||||
@@ -116,32 +116,14 @@ describe("ScriptInjectorService", () => {
|
|||||||
domainSettingsService.blockedInteractionsUris$ = of({ [mockBlockedURI.host]: null });
|
domainSettingsService.blockedInteractionsUris$ = of({ [mockBlockedURI.host]: null });
|
||||||
manifestVersionSpy.mockReturnValue(3);
|
manifestVersionSpy.mockReturnValue(3);
|
||||||
|
|
||||||
await expect(
|
await expect(scriptInjectorService["buildInjectionDetails"]).not.toHaveBeenCalled();
|
||||||
scriptInjectorService.inject({
|
|
||||||
tabId,
|
|
||||||
injectDetails: {
|
|
||||||
file: combinedManifestVersionFile,
|
|
||||||
frame: 10,
|
|
||||||
...sharedInjectDetails,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
).rejects.toThrow(expectedBlockedURIError);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("skips injecting the script in manifest v2 when the tab domain is a blocked domain", async () => {
|
it("skips injecting the script in manifest v2 when the tab domain is a blocked domain", async () => {
|
||||||
domainSettingsService.blockedInteractionsUris$ = of({ [mockBlockedURI.host]: null });
|
domainSettingsService.blockedInteractionsUris$ = of({ [mockBlockedURI.host]: null });
|
||||||
manifestVersionSpy.mockReturnValue(2);
|
manifestVersionSpy.mockReturnValue(2);
|
||||||
|
|
||||||
await expect(
|
await expect(scriptInjectorService["buildInjectionDetails"]).not.toHaveBeenCalled();
|
||||||
scriptInjectorService.inject({
|
|
||||||
tabId,
|
|
||||||
injectDetails: {
|
|
||||||
file: combinedManifestVersionFile,
|
|
||||||
frame: "all_frames",
|
|
||||||
...sharedInjectDetails,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
).rejects.toThrow(expectedBlockedURIError);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("injects the script in manifest v2 when given combined injection details", async () => {
|
it("injects the script in manifest v2 when given combined injection details", async () => {
|
||||||
|
|||||||
@@ -54,7 +54,10 @@ export class BrowserScriptInjectorService extends ScriptInjectorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!injectionAllowedInTab) {
|
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);
|
const injectionDetails = this.buildInjectionDetails(injectDetails, file);
|
||||||
|
|||||||
Reference in New Issue
Block a user