From 430d9093961f490d4a6a474013eeb7b6080b2260 Mon Sep 17 00:00:00 2001 From: Stefano Zini Date: Tue, 10 Nov 2026 14:51:20 +0100 Subject: [PATCH] ext: /health check blocks recording when the backend is offline, strobing offline alarm in popup --- README.md | 1 + app/ext/manifest.json | 2 +- app/ext/popup.html | 25 +++++++++++++++++++++++++ app/ext/popup.js | 23 +++++++++++++++++------ app/server.py | 3 +++ 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e78c37c..62ca2a5 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Base URL `http://127.0.0.1:18765`. | Method | Path | Params | |---|---|---| | GET | `/status` | all recordings + pipeline status | +| GET | `/health` | `ok` when the server is up (the extension checks it before recording) | | GET | `/report` | `name` → report HTML | | GET | `/pdf` | `name` → report PDF | | GET | `/search` | `q` → full-text search over transcripts/topics | diff --git a/app/ext/manifest.json b/app/ext/manifest.json index 65395e7..4808b9e 100644 --- a/app/ext/manifest.json +++ b/app/ext/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Teams Whisper Recorder", - "version": "1.1", + "version": "1.2", "description": "Record Teams tab audio+video (+mic) and transcribe with local whisper server", "permissions": ["tabCapture", "offscreen", "activeTab", "tabs", "declarativeNetRequest"], "host_permissions": ["http://127.0.0.1:18765/*", "https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"], diff --git a/app/ext/popup.html b/app/ext/popup.html index c58ad92..3db9a29 100644 --- a/app/ext/popup.html +++ b/app/ext/popup.html @@ -7,6 +7,18 @@ body[data-state=transcribing] { --accent: #2563eb; } body[data-state=done] { --accent: #16a34a; } body[data-state=error] { --accent: #d97706; } + body[data-state=offline] { --accent: #dc2626; } + #off { margin-bottom: 12px; padding: 12px 14px; border-radius: 8px; background: #fef2f2; border: 2px solid #dc2626; color: #7f1d1d; } + #off b { display: block; margin-bottom: 4px; font-size: 15px; color: #b91c1c; } + #off ol { margin: 8px 0 0; padding-left: 20px; } + body[data-state=offline] #st, body[data-state=offline] #txt { display: none; } + body[data-state=offline] #go:disabled { opacity: 1; background: #fecaca; color: #991b1b; } + /* Offline alarm: banner, button and dot strobe red/white. 0.4 s per cycle = 2.5 flashes/s, under the 3/s photosensitivity limit. + No prefers-reduced-motion opt-out on purpose: Windows with animations off reports "reduce" and would hide the alarm. */ + body[data-state=offline] #off { animation: strobe .4s steps(1) infinite; } + body[data-state=offline] #go:disabled, body[data-state=offline] .dot { animation: strobe .4s steps(1) infinite reverse; } + @keyframes strobe { 0% { background: #dc2626; color: #fff; border-color: #fff; } 50% { background: #fff; color: #b91c1c; border-color: #dc2626; } } + body[data-state=offline] #off b { color: inherit; } h1 { margin: 0 0 12px; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; } .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; } body[data-state=recording] .dot { animation: pulse 1.2s infinite; } @@ -18,14 +30,27 @@ #st { margin-top: 12px; padding: 8px 10px; background: #fff; border: 1px solid #e2e8f0; border-left: 3px solid var(--accent); border-radius: 6px; word-break: break-word; } #txt { margin: 12px 0 0; padding: 10px; white-space: pre-wrap; max-height: 260px; overflow: auto; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; font: 12px/1.45 ui-monospace, Consolas, monospace; } #txt:empty { display: none; } + #srv { margin-top: 8px; font-size: 12px; color: #475569; display: flex; align-items: center; gap: 6px; } + #srv::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; } + #srv[data-ok=true]::before { background: #16a34a; } + #srv[data-ok=false] { color: #dc2626; font-weight: 600; } + #srv[data-ok=false]::before { background: #dc2626; } a { display: inline-block; margin-top: 12px; color: #475569; font-size: 12px; }

Teams Whisper

+ +
+ +

 
diff --git a/app/ext/popup.js b/app/ext/popup.js
index b5b74ec..6a7c52c 100644
--- a/app/ext/popup.js
+++ b/app/ext/popup.js
@@ -6,16 +6,24 @@ const sendToOffscreen = message => chrome.runtime.sendMessage({ to: "off", ...me
 // Format milliseconds as m:ss.
 const formatElapsed = milliseconds => { const totalSeconds = Math.floor(milliseconds / 1000); return `${Math.floor(totalSeconds / 60)}:${String(totalSeconds % 60).padStart(2, "0")}`; };
 // Last error shown when there is no offscreen document to report it.
-let recorderState = { state: "idle" }, lastError = "";
+let recorderState = { state: "idle" }, lastError = "", serverOk = null;
+// Backend liveness (server.py /health); false on any error or after 1.5 s.
+const serverUp = () => fetch("http://127.0.0.1:18765/health", { signal: AbortSignal.timeout(1500) }).then(response => response.ok, () => false);
 
 // Refresh the button and status line from state recorderState.
 function render() {
   const goButton = byId("go"), statusLine = byId("st");
-  document.body.dataset.state = recorderState.state;
+// Backend down and not mid-recording: starting is impossible, the offline banner replaces the status line.
+  const offline = serverOk === false && recorderState.state !== "recording";
+  document.body.dataset.state = offline ? "offline" : recorderState.state;
+  byId("off").hidden = !offline;
 // Pipeline busy after stop: no new start until it finishes.
-  goButton.disabled = recorderState.state === "transcribing";
+  goButton.disabled = offline || recorderState.state === "transcribing";
+// Backend indicator under the button.
+  byId("srv").dataset.ok = serverOk ?? "";
+  byId("srv").textContent = serverOk == null ? "server: checking..." : serverOk ? "server: online" : "server: OFFLINE";
 // Button doubles as Stop while recording.
-  goButton.textContent = recorderState.state === "recording" ? "Stop + transcribe" : "Start";
+  goButton.textContent = offline ? "Recording blocked: server offline" : recorderState.state === "recording" ? "Stop + transcribe" : "Start";
 // Status line text per recorder state.
   statusLine.textContent = {
     idle: "idle - open a Teams tab and press Start",
@@ -30,8 +38,9 @@ function render() {
 
 // Poll the recorder state every second.
 async function poll() {
-// Offscreen doc exists: ask it for its state. Otherwise show the last error, or idle.
-  if (await chrome.offscreen.hasDocument()) recorderState = (await sendToOffscreen({ cmd: "status" })) || recorderState; else recorderState = lastError ? { state: "error", text: lastError } : { state: "idle" };
+// A failed Start wins; else ask the offscreen doc (if any) for its state, or show idle.
+  recorderState = lastError ? { state: "error", text: lastError } : (await chrome.offscreen.hasDocument()) ? (await sendToOffscreen({ cmd: "status" })) || recorderState : { state: "idle" };
+  serverOk = await serverUp();
   render();
 }
 
@@ -54,6 +63,8 @@ byId("go").onclick = async () => {
     if (activeTab.url?.startsWith("chrome-extension:")) throw new Error("This is the extension's own page. Switch to the Teams tab, then click the icon.");
 // Stream id that the offscreen document later passes to getUserMedia.
     const streamId = await chrome.tabCapture.getMediaStreamId({ targetTabId: activeTab.id });
+// Health check before recording: backend down = nothing would be saved, so show the offline banner and stop here.
+    if (!(serverOk = await serverUp())) return render();
 // Create the offscreen document once; it stays alive while recording.
     if (!(await chrome.offscreen.hasDocument()))
       await chrome.offscreen.createDocument({ url: "offscreen.html", reasons: ["USER_MEDIA"], justification: "record tab" });
diff --git a/app/server.py b/app/server.py
index b543b18..a093fde 100644
--- a/app/server.py
+++ b/app/server.py
@@ -859,6 +859,9 @@ class Handler(BaseHTTPRequestHandler):
             )
         elif parsed.path == "/status":
             self._json(status())
+        # Cheap liveness probe for the extension (checked before recording starts).
+        elif parsed.path == "/health":
+            self._send(b"ok")
         elif parsed.path == "/report":
             file_path = out_root / name / "report.html"
             self._send(