Skip to content

Commit

Permalink
convert thrown error on content script injection block to a warning a…
Browse files Browse the repository at this point in the history
…nd early return
  • Loading branch information
jprusik committed Dec 23, 2024
1 parent 47b5b89 commit ee6df26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -70,6 +69,7 @@ describe("ScriptInjectorService", () => {
platformUtilsService,
logService,
);
jest.spyOn(scriptInjectorService as any, "buildInjectionDetails");
});

describe("inject", () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 57 in apps/browser/src/platform/services/browser-script-injector.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/services/browser-script-injector.service.ts#L57

Added line #L57 was not covered by tests
`${injectDetails.file} was not injected because ${tabURL?.hostname || "the tab URI"} is on the user's blocked domains list.`,
);
return;

Check warning on line 60 in apps/browser/src/platform/services/browser-script-injector.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/services/browser-script-injector.service.ts#L60

Added line #L60 was not covered by tests
}

const injectionDetails = this.buildInjectionDetails(injectDetails, file);
Expand Down

0 comments on commit ee6df26

Please sign in to comment.