OLD | NEW |
(Empty) | |
| 1 def main(request, response): |
| 2 # Set mode to 'init' for initial fetch. |
| 3 mode = 'init' |
| 4 if 'update-recovery-mode' in request.cookies: |
| 5 mode = request.cookies['update-recovery-mode'].value |
| 6 |
| 7 # no-cache itself to ensure the user agent finds a new version for each upda
te. |
| 8 headers = [('Cache-Control', 'no-cache, must-revalidate'), |
| 9 ('Pragma', 'no-cache')] |
| 10 |
| 11 extra_body = '' |
| 12 |
| 13 if mode == 'init': |
| 14 # Install a bad service worker that will break the controlled |
| 15 # document navigation. |
| 16 response.set_cookie('update-recovery-mode', 'bad') |
| 17 extra_body = "addEventListener('fetch', function(e) { e.respondWith(Prom
ise.reject()); });" |
| 18 elif mode == 'bad': |
| 19 # When the update tries to pull the script again, update to |
| 20 # a worker service worker that does not break document |
| 21 # navigation. Serve the same script from then on. |
| 22 response.delete_cookie('update-recovery-mode') |
| 23 |
| 24 headers.append(('Content-Type', 'application/javascript')) |
| 25 return headers, '%s' % (extra_body) |
OLD | NEW |