()
| 57 | } |
| 58 | |
| 59 | function waitForBroadcast(): Promise<boolean> { |
| 60 | return new Promise((resolve) => { |
| 61 | const channel = new BroadcastChannel(CHANNEL_NAME); |
| 62 | |
| 63 | const cleanup = (received: boolean) => { |
| 64 | channel.close(); |
| 65 | resolve(received); |
| 66 | }; |
| 67 | |
| 68 | const timeout = setTimeout(() => cleanup(false), WAIT_TIMEOUT_MS); |
| 69 | |
| 70 | channel.onmessage = () => { |
| 71 | clearTimeout(timeout); |
| 72 | cleanup(true); |
| 73 | }; |
| 74 | }); |
| 75 | } |