Skip to content

Commit

Permalink
testing service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdesl committed May 24, 2016
1 parent 91e3bc2 commit 5ffe756
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
};
}

// Enable service workers
electron.webFrame.registerURLSchemeAsPrivileged('file');
electron.webFrame.registerURLSchemeAsSecure('file');
electron.webFrame.registerURLSchemeAsBypassingCSP('file');

// hook into the internal require for a few features:
// - better error reporting on syntax errors and missing modules
// - require.main acts like node.js CLI
Expand Down
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ app.on('quit', function () {
});

app.on('ready', function () {
electron.protocol.registerServiceWorkerSchemes(['file:']);

// Get starting HTML file
var htmlFile = path.resolve(__dirname, 'lib', 'index.html');
var customHtml = false; // if we should watch it as well
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// The SW will be shutdown when not in use to save memory,
// be aware that any global state is likely to disappear
console.log("SW startup");

self.addEventListener('install', function(event) {
console.log("SW installed");
});

self.addEventListener('activate', function(event) {
console.log("SW activated");
});

self.addEventListener('fetch', function(event) {
console.log("Caught a fetch!");
event.respondWith(new Response("Hello world!"));
});

0 comments on commit 5ffe756

Please sign in to comment.