Skip to content

Instantly share code, notes, and snippets.

View gauntface's full-sized avatar
🤓
Mon-Fri: Working. Sat-Sun: Not Working.

Matt Gaunt-Seo gauntface

🤓
Mon-Fri: Working. Sat-Sun: Not Working.
View GitHub Profile
@gauntface
gauntface / sw-test-cleaup.js
Last active April 22, 2024 05:02
Function to unregister SW and clear out old caches.
window.__testCleanup = () => {
const unregisterSW = () => {
return navigator.serviceWorker.getRegistrations()
.then((registrations) => {
const unregisterPromise = registrations.map((registration) => {
return registration.unregister();
});
return Promise.all(unregisterPromise);
});
};
app.use('/', express.static(rootDirectory, {
setHeaders: (res) => {
res.setHeader('Service-Worker-Allowed', '/');
},
}));
@gauntface
gauntface / sw-unit-tests.js
Created March 6, 2017 22:06
An example of Mocha running in a service worker / web worker.
importScripts('/node_modules/mocha/mocha.js');
mocha.setup({
ui: 'bdd',
reporter: null,
});
describe('First SW Test Suite', function() {
it('should test something', function() {
...
@gauntface
gauntface / toggle-remote-styles.js
Last active March 12, 2020 12:56
A book marklet to toggle styles.
javascript:(function(){var styles = document.querySelectorAll('link[rel=\'stylesheet\']'); for (var s = 0; s < styles.length; s++) {styles[s].mediax = styles[s].media;if (styles[s].media === 'only x') { styles[s].media = styles[s].mediax; } else if (styles[s].media !== 'print') {styles[s].media = 'only x';}}})();
@gauntface
gauntface / sw.js
Created January 6, 2020 04:42
Trying to debug sw
function tryCache(event) {
console.log('Got request: ', event.request);
return caches.match(event.request)
.then((response) => {
if (response) {
console.log("Cache hit ", response);
return response;
}
@gauntface
gauntface / my-first-test.js
Created March 6, 2017 21:59
Adding function to unregister service workers.
describe('Service Worker Suite', function() {
beforeEach(function() {
return navigator.serviceWorker.getRegistrations()
.then((registrations) => {
const unregisterPromises = registrations.map((registration) => {
return registration.unregister();
});
return Promise.all(unregisterPromises);
});
if (process.env.NODE_ENV !== 'production' && this.checkEntryRevisioning === true) {
showWarningsIfNeeded(userEntries);
}
if (process.env.NODE_ENV !== 'production')
if (this.checkEntryRevisioning === true) {
showWarningsIfNeeded(userEntries);
}
}
# Misc Addons/Configs
dist: trusty
sudo: required
addons:
apt:
sources:
- google-chrome
- ubuntu-toolchain-r-test
packages:
- google-chrome-stable
import Route from 'workbox-routing/Route';