Last active
June 7, 2024 12:08
-
-
Save EduardoAC/eeb457de36941e2e4bc04e807b766a20 to your computer and use it in GitHub Desktop.
Chrome Extension - Site Page Review - Message Handler. The goal of this function is to orchestrate the messages received by the content scripts and proxy them to the right handler.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MessageRate } from "../../types/message.types" | |
import { ratingMessageHandler } from "./onMessageHandlers/ratingMessageHandler" | |
export function messageHandler( | |
message: Message, | |
sender: chrome.runtime.MessageSender, | |
sendResponse: SendResponseCallback, | |
) { | |
if (sender.tab && message.type) { | |
switch (message.type) { | |
case "rating": | |
ratingMessageHandler( | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
message as any as Message<MessageRate>, | |
sendResponse, | |
) | |
break | |
default: | |
return false | |
} | |
return true // We will process the messages asynchronously | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The project example of a site page review can be found at https://github.com/EduardoAC/site-review-extension.
Also, the code for the message sender can be found at https://gist.github.com/EduardoAC/000b1e39a6ec10a892e7c6cd93730a53.