Overview
Posture!Posture!Posture! is a Chrome extension built with React and TensorFlow.js that uses your webcam to monitor posture while browsing. The extension follows the standard Chrome Extension Manifest V3 architecture with four main components:- Background Service Worker - Message relay and badge management
- Options Page - Webcam interface and pose detection logic
- Popup - Quick controls for starting/stopping tracking
- Content Script - Visual feedback on web pages
Extension Structure
- Background
- Options Page
- Popup
- Content Script
The background service worker acts as a message relay between the Options page and Content script.File:
src/pages/Background/index.jsResponsibilities:- Manages extension badge (ON/OFF status)
- Relays posture detection messages from Options to Content script
- Establishes port connections for real-time communication
Manifest Configuration
The extension uses Manifest V3 with the following key configurations:The content script runs on all HTTP and HTTPS pages to provide posture feedback across your entire browsing experience.
Communication Flow
The extension uses Chrome’s port-based messaging for real-time communication:Message Flow Example
- Options detects bad posture → sends
{ posture: 'bad' }via port - Background receives message → relays to active tab’s Content script
- Content Script receives message → adds
bad-postureclass to body - User sees “Sit Up Straight!” banner on the page
Directory Structure
Technology Stack
- React - UI component library
- TypeScript - Type-safe JavaScript (Options, Content)
- TensorFlow.js - Machine learning in the browser
- MoveNet - Pose detection model
- react-webcam - Webcam access component
- Chrome Extension APIs - Messaging, storage, and extension lifecycle
Why port-based messaging?
Why port-based messaging?
Port-based messaging (
chrome.runtime.connect) is used instead of one-time messages (chrome.runtime.sendMessage) because the extension needs continuous, real-time communication between components. The Options page sends posture updates approximately every 100ms, making persistent connections more efficient than establishing new connections for each message.