Skip to content

Commit

Permalink
Fix bug introduced in v0.4.1 where no command is able to run if there…
Browse files Browse the repository at this point in the history
… is no content script
  • Loading branch information
david-tejada committed Apr 28, 2023
1 parent 9bceeb1 commit 13cfb1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 20 additions & 1 deletion e2e/noContentScript.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { clipboard } from "@nut-tree/nut-js";
import { ResponseToTalon } from "../src/typings/RequestFromTalon";
import { rangoCommandWithTarget } from "./utils/rangoCommands";
import {
rangoCommandWithTarget,
rangoCommandWithoutTarget,
} from "./utils/rangoCommands";
import { sleep } from "./utils/testHelpers";

beforeEach(async () => {
Expand All @@ -20,3 +23,19 @@ describe("Direct clicking", () => {
expect(found).toBeTruthy();
});
});

describe("Background commands", () => {
test("Commands that don't need the content script are still able to run", async () => {
await rangoCommandWithoutTarget("copyLocationProperty", "href");
const clip = await clipboard.getContent();
const response = JSON.parse(clip) as ResponseToTalon;
const action = response.actions[0]!;

expect(action).toBeDefined();

const textToCopy = action.textToCopy;

expect(textToCopy).toBeDefined();
expect(textToCopy).toBe("chrome://new-tab-page/");
});
});
7 changes: 6 additions & 1 deletion src/background/commands/dispatchCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ const backgroundCommands = new Set([
export async function dispatchCommand(
command: RangoAction
): Promise<ResponseToTalon> {
await sendRequestToContent({ type: "allowToastNotification" });
try {
await sendRequestToContent({ type: "allowToastNotification" });
} catch {
// No content script. We do nothing.
}

const result = (await (backgroundCommands.has(command.type)
? runBackgroundCommand(command)
: sendRequestToContent(command))) as string | TalonAction[] | undefined;
Expand Down

0 comments on commit 13cfb1d

Please sign in to comment.