mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
33bf6126a9
This helper script will allow us to run the same test across both HTTP and HTTPS origins. This patch also uses postMessage instead of a direct function call on the parent window, because in the HTTPS case, that window will be cross-origin. It also moves the code to trigger the update and get the corresponding updatefound event to wait_for_update.html, since getting the service worker registration cross-origin is not possible. --HG-- extra : rebase_source : 4df46df635f6445f286b54a8a3d9b2e3f8b8447a
25 lines
754 B
JavaScript
25 lines
754 B
JavaScript
function handleRequest(request, response) {
|
|
var stateName = request.scheme + 'periodiccounter';
|
|
if (request.queryString == 'clearcounter') {
|
|
setState(stateName, '');
|
|
return;
|
|
}
|
|
|
|
if (!getState(stateName)) {
|
|
setState(stateName, '1');
|
|
} else {
|
|
// Make sure that we pass a string value to setState!
|
|
setState(stateName, "" + (parseInt(getState(stateName)) + 1));
|
|
}
|
|
response.setHeader("Content-Type", "application/javascript", false);
|
|
response.write(getScript(stateName));
|
|
}
|
|
|
|
function getScript(stateName) {
|
|
return "onfetch = function(e) {" +
|
|
"if (e.request.url.indexOf('get-sw-version') > -1) {" +
|
|
"e.respondWith(new Response('" + getState(stateName) + "'));" +
|
|
"}" +
|
|
"};";
|
|
}
|