Implemented a reusable browser tab visibility and notification handling framework in OutSystems Reactive Web using JavaScript and reusable blocks.
The solution is designed using a modular architecture with separate reusable blocks for:
Browser tab visibility detection
Event propagation to screens
Browser notification handling
This allows centralized management of browser activity detection and notification triggering across the application.
A reusable block named TabVisibilityListener is created to monitor browser tab activity.
TabVisibilityListener
The block detects:
When the user switches away from the current tab
When the user returns to the application tab
Browser minimize/restore scenarios
This is achieved using the JavaScript Browser Visibility API with the visibilitychange event.
visibilitychange
Inside the block:
OnReady lifecycle event is used
OnReady
A RunJavaScript node registers the visibility listener
RunJavaScript
JavaScript logic:
Detects document.hidden
document.hidden
Triggers events back to OutSystems based on visibility state
Example behavior:
If document.hidden = true? User left the tab
document.hidden = true
If document.hidden = false? User returned to the tab
document.hidden = false
To prevent duplicate event listeners during rerenders or navigation:
A global window flag is maintained before registering listeners
Example:
window.visibilityListenerAdded
The block exposes reusable OutSystems events:
OnTabHidden
OnTabVisible
These events can be handled directly from any parent screen where the block is used.
This creates a clean separation between:
Browser event detection
Business logic handling
The TabVisibilityListener block is added to screens requiring visibility tracking.
The screen subscribes to:
This enables screen-specific behaviors such as:
Marking user as away
Pausing live refresh
Tracking session activity
Triggering alerts
Logging activity timestamps
Updating user presence
Example flow:
User switches browser tab ? visibilitychange event fires ? TabVisibilityListener detects state ? Block event triggered ? Screen handles event ? Business logic executed
A separate reusable component named BrowserNotification is implemented for notification handling.
BrowserNotification
The component provides centralized browser notification management using the JavaScript Notification API.
The notification component accepts:
Title
Message
Optional future enhancements:
Icon
ClickAction
Tag
RequireInteraction
Silent
AutoCloseDuration
The component:
Checks notification permission
Requests permission if not already granted
Displays browser/system notifications
Notifications can appear:
While user is on another tab
When browser is minimized
When application tab is inactive
Example scenarios:
Procurement approval pending
New chatbot response
Workflow escalation
Task assignment
Reminder alerts
The listener and notification logic can be reused across all screens without duplicating JavaScript.
Detection, event handling, and notification logic are separated into independent components.
New visibility behaviors or notification types can be added without modifying individual screens.
Changes to browser handling logic are centralized within reusable blocks.
The approach aligns well with SPA architecture patterns commonly used in:
Teams
Slack
WhatsApp Web
Enterprise dashboards
Potential future improvements:
Idle detection
Multi-tab synchronization
Online/away/offline presence tracking
Real-time session heartbeat APIs
Firebase push notification integration
Background service worker notifications
Notification throttling/debouncing
User preference management
TabVisibilityListener Block ? Detects browser visibility changes ? Triggers OutSystems events ? Screen handles events ? BrowserNotification action/block invoked ? Browser notification displayed
This implementation provides a clean, scalable, and reusable solution for browser activity monitoring and notification management within OutSystems Reactive Web applications.