From 69dcf1bc0c13f293c01592545ec2ccb1111d5f3e Mon Sep 17 00:00:00 2001 From: Navid Shad Date: Wed, 13 May 2026 20:01:45 +0300 Subject: [PATCH] feat: announce extension presence on dashboard origins for install nudge #86exkh0z3 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/plugins/modular-rest.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/plugins/modular-rest.ts b/src/plugins/modular-rest.ts index 203bc7b..d6d07fa 100644 --- a/src/plugins/modular-rest.ts +++ b/src/plugins/modular-rest.ts @@ -38,6 +38,38 @@ if (typeof Storage !== "undefined" && isDashboardOrigin()) { }; } +// Announce extension presence to the dashboard so it can hide the "install +// the extension" nudge. window.postMessage crosses the content-script / +// page-world boundary; the message is scoped to the page's own origin. +if (typeof window !== "undefined" && isDashboardOrigin()) { + const announcePresence = () => { + try { + window.postMessage( + { + source: "subturtle-extension", + type: "presence", + version: chrome.runtime.getManifest().version, + }, + window.location.origin + ); + } catch (_e) { + // postMessage can fail in odd sandboxed iframes — non-fatal. + } + }; + + // Announce immediately in case the dashboard listener is already attached. + announcePresence(); + + // Respond to dashboard pings in case the dashboard mounts after us. + window.addEventListener("message", (event) => { + if (event.source !== window) return; + const data = event.data; + if (data?.source === "subturtle-dashboard" && data?.type === "ping") { + announcePresence(); + } + }); +} + import { GlobalOptions, authentication } from "@modular-rest/client"; import { sendMessage, sendMessageToTabs } from "../common/helper/massage";