index.html 631 B

12345678910111213141516171819
  1. <script>
  2. const ipcRenderer = require('electron').ipcRenderer;
  3. navigator.serviceWorker.register('service-worker.js', {scope: './'}).then(function() {
  4. if (navigator.serviceWorker.controller) {
  5. var xhr = new XMLHttpRequest();
  6. xhr.open('GET', 'http://dummy/echo');
  7. xhr.setRequestHeader('X-Mock-Response', 'yes');
  8. xhr.addEventListener('load', function() {
  9. ipcRenderer.send('response', xhr.responseText);
  10. });
  11. xhr.send();
  12. } else {
  13. ipcRenderer.send('reload');
  14. }
  15. }).catch(function(error) {
  16. ipcRenderer.send('error', `${error.message}\n${error.stack}`);
  17. })
  18. </script>