| 39 | } |
| 40 | |
| 41 | async function tryAcquireAndRefresh(): Promise<boolean> { |
| 42 | return navigator.locks.request( |
| 43 | LOCK_NAME, |
| 44 | { ifAvailable: true }, |
| 45 | async (lock) => { |
| 46 | if (!lock) { |
| 47 | return false; |
| 48 | } |
| 49 | await authServiceClientConnect.refresh({}); |
| 50 | // Only broadcast on success - failure lets waiting tabs timeout and retry |
| 51 | const channel = new BroadcastChannel(CHANNEL_NAME); |
| 52 | channel.postMessage("complete"); |
| 53 | channel.close(); |
| 54 | return true; |
| 55 | } |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | function waitForBroadcast(): Promise<boolean> { |
| 60 | return new Promise((resolve) => { |