diff --git a/src/background/Application.ts b/src/background/Application.ts index 0d9275bc..f43b59bd 100644 --- a/src/background/Application.ts +++ b/src/background/Application.ts @@ -80,7 +80,11 @@ export default class Application { private async onFindPortConnect(port: chrome.runtime.Port) { const tabId = port.sender?.tab?.id; const frameId = port.sender?.frameId; - if (typeof tabId === "undefined" || typeof frameId === "undefined") { + if ( + typeof tabId === "undefined" || + typeof frameId === "undefined" || + port.sender?.url === "about:blank" + ) { return; } diff --git a/src/background/messaging/BackgroundMessageListener.ts b/src/background/messaging/BackgroundMessageListener.ts index f0638236..a648cf1a 100644 --- a/src/background/messaging/BackgroundMessageListener.ts +++ b/src/background/messaging/BackgroundMessageListener.ts @@ -15,8 +15,6 @@ export default class BackgroundMessageListener { private readonly receiver: ReceiverWithContext = new ReceiverWithContext(); - private readonly consolePorts: { [tabId: number]: chrome.runtime.Port } = {}; - constructor( @inject(SettingsController) settingsController: SettingsController, @@ -63,9 +61,6 @@ export default class BackgroundMessageListener { this.receiver .route("settings.validate") .to(settingsController.validate.bind(settingsController)); - this.receiver - .route("console.frame.message") - .to(this.onConsoleFrameMessage.bind(this)); this.receiver .route("press.key") .to(keyController.pressKey.bind(keyController)); @@ -117,31 +112,5 @@ export default class BackgroundMessageListener { return true; }, ); - chrome.runtime.onConnect.addListener(this.onConnected.bind(this)); - } - - private onConnected(port: chrome.runtime.Port): void { - if (port.name !== "vimmatic-console") { - return; - } - - if (port.sender && port.sender.tab && port.sender.tab.id) { - const id = port.sender.tab.id; - this.consolePorts[id] = port; - } - } - - private onConsoleFrameMessage( - { sender }: RequestContext, - message: any, - ): void { - if (typeof sender.tab?.id === "undefined") { - return; - } - const port = this.consolePorts[sender.tab?.id]; - if (!port) { - return; - } - port.postMessage(message); } } diff --git a/src/console/App.tsx b/src/console/App.tsx index 3e2d4ae9..61e0d23f 100644 --- a/src/console/App.tsx +++ b/src/console/App.tsx @@ -69,10 +69,6 @@ const App: React.FC = () => { chrome.runtime.onMessage.addListener((message: any) => { receiver.receive(message.type, message.args); }); - const port = chrome.runtime.connect({ name: "vimmatic-console" }); - port.onMessage.addListener((message: any) => { - receiver.receive(message.type, message.args); - }); sendReady(); }, []); diff --git a/src/content/client/ConsoleClient.ts b/src/content/client/ConsoleClient.ts deleted file mode 100644 index 26ec8614..00000000 --- a/src/content/client/ConsoleClient.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { injectable, inject } from "inversify"; -import type BackgroundMessageSender from "./BackgroundMessageSender"; - -export default interface ConsoleClient { - info(text: string): Promise; - error(text: string): Promise; -} - -@injectable() -export class ConsoleClientImpl implements ConsoleClient { - constructor( - @inject("BackgroundMessageSender") - private readonly sender: BackgroundMessageSender, - ) {} - - async info(text: string): Promise { - this.sender.send("console.frame.message", { - message: { - type: "console.show.info", - text, - }, - }); - } - - async error(text: string): Promise { - this.sender.send("console.frame.message", { - message: { - type: "console.show.error", - text, - }, - }); - } -} diff --git a/src/content/di.ts b/src/content/di.ts index e3f261ab..95cd6167 100644 --- a/src/content/di.ts +++ b/src/content/di.ts @@ -3,7 +3,6 @@ import { AddonEnabledRepositoryImpl } from "./repositories/AddonEnabledRepository"; import { AddressRepositoryImpl } from "./repositories/AddressRepository"; import { ClipboardRepositoryImpl } from "./repositories/ClipboardRepository"; -import { ConsoleClientImpl } from "./client/ConsoleClient"; import { ConsoleFramePresenterImpl } from "./presenters/ConsoleFramePresenter"; import { FocusPresenterImpl } from "./presenters/FocusPresenter"; import { HintPresenterImpl } from "./presenters/HintPresenter"; @@ -28,7 +27,6 @@ const container = new Container({ autoBindInjectable: true }); container.bind("AddonEnabledRepository").to(AddonEnabledRepositoryImpl); container.bind("AddressRepository").to(AddressRepositoryImpl); container.bind("ClipboardRepository").to(ClipboardRepositoryImpl); -container.bind("ConsoleClient").to(ConsoleClientImpl); container.bind("ConsoleFramePresenter").to(ConsoleFramePresenterImpl); container.bind("FocusPresenter").to(FocusPresenterImpl); container.bind("HintPresenter").to(HintPresenterImpl); diff --git a/src/content/presenters/FindPresenter.ts b/src/content/presenters/FindPresenter.ts index d229adb9..98c66c42 100644 --- a/src/content/presenters/FindPresenter.ts +++ b/src/content/presenters/FindPresenter.ts @@ -14,7 +14,12 @@ export class FindPresenterImpl implements FindPresenter { // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work // because of same origin policy - return window.find(keyword, caseSensitive, backwards, wrapScan); + try { + return window.find(keyword, caseSensitive, backwards, wrapScan); + } catch (e) { + // Firefox throws NS_ERROR_ILLEGAL_VALUE sometimes + return false; + } } clearSelection(): void { diff --git a/src/messaging/schema/background.ts b/src/messaging/schema/background.ts index 45d488ad..4e5d8575 100644 --- a/src/messaging/schema/background.ts +++ b/src/messaging/schema/background.ts @@ -5,7 +5,6 @@ import { Duplex } from "../types"; export type Schema = { "typeof addon.enabled.response": Duplex<{ enabled: boolean }>; - "console.frame.message": Duplex<{ message: any }>; "background.operation": Duplex<{ repeat: number; op: Operation; diff --git a/test/content/mock/MockConsoleClient.ts b/test/content/mock/MockConsoleClient.ts deleted file mode 100644 index 849c00d1..00000000 --- a/test/content/mock/MockConsoleClient.ts +++ /dev/null @@ -1,24 +0,0 @@ -import ConsoleClient from "../../../src/content/client/ConsoleClient"; - -export default class MockConsoleClient implements ConsoleClient { - public isError: boolean; - - public text: string; - - constructor() { - this.isError = false; - this.text = ""; - } - - info(text: string): Promise { - this.isError = false; - this.text = text; - return Promise.resolve(); - } - - error(text: string): Promise { - this.isError = true; - this.text = text; - return Promise.resolve(); - } -}