browser.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.type === "GET_CONTEXT_STACK") { const contextStack = window.wrappedJSObject.getContextStack(); sendResponse({ contextStack }); } else if (message.type === "UPDATE_CONTEXT_VALUE") { const { key, value, depth } = message; if (window.wrappedJSObject.updateContextValue) { window.wrappedJSObject.updateContextValue(key, value, depth); sendResponse({ success: true }); } else { sendResponse({ success: false, error: "updateContextValue not defined", }); } } }); browser.runtime.sendMessage({ type: "PAGE_LOADED" });