Add a guard on the browser side that refuses to execute in-flight requests when the tab is hidden or inactive. This is defense in depth: even if the session cache has stale presence data, the browser is the final enforcer.
Behavior per caller type:
- Third-party agents: hard fail with a descriptive error, so the agent can prompt the user to switch back to the tab
- First-party agents: queue the action until the tab is refocused, then execute (the user started a conversation intentionally and shouldn't be penalized for briefly switching tabs)
The in-flight request payload should carry a property indicating whether the request originates from a first-party or third-party caller, so the gate can differentiate.
Visibility/focus tracking uses the Page Visibility API (visibilitychange event) and window.focus/blur events.
Add a guard on the browser side that refuses to execute in-flight requests when the tab is hidden or inactive. This is defense in depth: even if the session cache has stale presence data, the browser is the final enforcer.
Behavior per caller type:
The in-flight request payload should carry a property indicating whether the request originates from a first-party or third-party caller, so the gate can differentiate.
Visibility/focus tracking uses the Page Visibility API (
visibilitychangeevent) andwindow.focus/blurevents.