diff --git a/background.js b/background.js index 8d07025..f1762ce 100644 --- a/background.js +++ b/background.js @@ -1,9 +1,13 @@ -chrome.webNavigation.onHistoryStateUpdated.addListener( - function (details) { - console.log("onHistoryStateUpdated", details); - chrome.tabs.sendMessage(details.tabId, { - type: "navigation", - }); - }, - { url: [{ hostSuffix: "github.com" }] } -); +chrome.webNavigation.onHistoryStateUpdated.addListener((details) => { + chrome.tabs.sendMessage(details.tabId, { + type: "navigation", + }, () => { + if (chrome.runtime.lastError) { + // We need to handle + console.warn("Error sending message:", chrome.runtime.lastError.message); + } else { + console.log("Message successfully received by content script."); + } + }); + +}, { url: [{ hostSuffix: "github.com" }] }) diff --git a/src/index.js b/src/index.js index 7c4b1f1..d882452 100644 --- a/src/index.js +++ b/src/index.js @@ -2,8 +2,11 @@ import { appendAccessibilityInfo } from "./utils.js"; export async function initialize() { /* Listen for messages from the background script */ - chrome.runtime.onMessage.addListener(() => { - appendAccessibilityInfo(); + chrome.runtime.onMessage.addListener((message, sendResponse) => { + if (message.type === "navigation") { + sendResponse({ status: "ok" }); + appendAccessibilityInfo(); + } }); appendAccessibilityInfo();