diff --git a/src/teampulse/monitor.py b/src/teampulse/monitor.py index 3f2313b..74ae97b 100644 --- a/src/teampulse/monitor.py +++ b/src/teampulse/monitor.py @@ -20,7 +20,10 @@ _POLL_JS = r"""() => { const msgs = []; // Channel meeting: channel-pane-message contains reply-message-header + message-body siblings - const channelPanes = document.querySelectorAll("[data-tid='channel-pane-message']"); + // Filter to visible elements only — Teams SPA keeps hidden/cached panes in the DOM + const channelPanes = Array.from( + document.querySelectorAll("[data-tid='channel-pane-message']") + ).filter(el => el.offsetParent !== null); if (channelPanes.length > 0) { channelPanes.forEach((pane, paneIdx) => { const els = pane.querySelectorAll( @@ -49,8 +52,10 @@ _POLL_JS = r"""() => { return msgs; } - // Meeting chat: chat-pane-message with message-author-name inside - document.querySelectorAll("[data-tid='chat-pane-message']").forEach((msg, idx) => { + // Meeting chat: chat-pane-message with message-author-name inside (visible only) + Array.from(document.querySelectorAll("[data-tid='chat-pane-message']")) + .filter(el => el.offsetParent !== null) + .forEach((msg, idx) => { const senderEl = msg.querySelector("[data-tid='message-author-name']"); const sender = senderEl ? senderEl.innerText.trim() : ''; if (!sender) return;