| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> |
| </head> |
| <body> |
| <script> |
| var activeWorker; |
| var registration; |
| async function doTest() |
| { |
| registration = await navigator.serviceWorker.register("third-party-worker.js", { scope : "." }); |
| activeWorker = registration.installing; |
| await new Promise((resolve, reject) => { |
| activeWorker.addEventListener('statechange', () => { |
| if (activeWorker.state === "activated") |
| resolve(); |
| }); |
| setTimeout(reject, 5000); |
| }); |
| } |
| window.onmessage = async (e) => { |
| try { |
| await doTest(); |
| navigator.serviceWorker.onmessage = async (e) => { |
| await registration.unregister(); |
| parent.postMessage(e.data, '*'); |
| } |
| activeWorker.postMessage(e.data); |
| } catch (e) { |
| if (registration) |
| registration.unregister(); |
| parent.postMessage("FAILED: " + e, '*'); |
| } |
| } |
| </script> |
| </body> |
| </html> |