-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: add smoketest for slow service worker #6648
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,32 @@ <h4> | |
</h4> | ||
|
||
<script> | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker.register('/offline-ready-sw.js').then(function(registration) { | ||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)) | ||
} | ||
|
||
async function registerServiceWorker(qs = '') { | ||
if (!('serviceWorker' in navigator)) return | ||
|
||
try { | ||
const registration = await navigator.serviceWorker.register(`/offline-ready-sw.js${qs}`) | ||
console.log('service worker registration complete'); | ||
|
||
registration.addEventListener('statechange', e => { | ||
console.log('sw registration is now', e.target.state); | ||
}); | ||
}).catch(function(e) { | ||
} catch (e) { | ||
console.error('service worker is not so cool.', e); | ||
throw e; | ||
}); | ||
} | ||
} | ||
|
||
if (window.location.search.includes('slow')) { | ||
setTimeout(() => registerServiceWorker('?delay=5000&slow'), 500); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it make any difference to do this on "load", where the load event is deferred by a significant amount of time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This the load event is currently being delayed by an image farther down that takes 2s, the only way LH doesn't catch service worker AFAICT is if the page doesn't call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK this (registering SW on "load") is basically what pintrest.com (which LH says has no SW) does. not sure if the key difference is how long until "load" fires - or something else entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that's all they're doing, then I'm not sure what's going on there. We always wait until load so unless their load event handlers take a very long time such that we don't get to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can take a look closer at pinterest if there's not already too many cooks in the kitchen :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's at most 1 :) IDK if @wardpeet ever started on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha, alright I'll poke around. |
||
} else { | ||
registerServiceWorker(); | ||
} | ||
|
||
</script> | ||
|
||
<!-- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we check for this anywhere? Or is the hope that a smoke test will fail and this would be used for debugging.
Maybe we should be pulling in
errors-in-console
into all our smoke tests :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope
Bingo!
Not a bad idea, followup! :D