Demo for cross site tab change detection
- You can distinguish tab switching on the same site when a script is injected on all the tabs of the site
- You cannot distinguish whether the tab became activated or switched from another site
- Start server
$ git clone git@github.com:yujiosaka/cross-site-tab-change-detection.git
$ npm install
$ npm run build
$ npm start
- Open http://localhost:8080 in multiple tabs
Broadcast Channel | Shared Worker | LocalStorage | WebSocket (SocketIO) | |
---|---|---|---|---|
Code simplicity | ○ | △ | ○ | × |
Server load | ○ | ○ | ○ | △ |
Client load | ○ | ○ | △ 1 | ○ |
Responsiveness | △ 2 | ○ | ○ | × 3 |
Cross origin support | × | × | × | ○ |
Chrome | 54 | 4 | 4 | 10.13 |
Edge | <=79 | 79 | 12 | ○ |
Firefox | 38 | 29 | 3.5 | 10.11 |
Internet Explorer | × | × | 8 | 7 |
Opera | 41 | 10.6 | 10.5 | ○ |
Safari | × | × | 4 | 10.13 |
- Choose Broadcast Channel only when code simplicity is your primary concern
- Choose Shared Worker when
- You don't need to support Internet Explorer
- You don't need to support cross origins
- You don't want to place loads on both client and server side
- Choose LocalStorage when
- You need to support Internet Explorer
- You don't need to support cross origins
- You don't want to place loads on server side
- Choose WebSocket when
- You need to support Internet Explorer
- You need to support cross origins
- You don't want to place loads on client side