a tiny oauth browser client for atproto using a service worker
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix fetch handler in chrome

+26 -20
+13 -10
atsw.js
··· 302 302 if (typeof ServiceWorkerGlobalScope !== "undefined" && sw instanceof ServiceWorkerGlobalScope) { 303 303 sw.oninstall = () => sw.skipWaiting(); 304 304 sw.onactivate = (e) => e.waitUntil(sw.clients.claim()); 305 - sw.onfetch = async (e) => { 306 - const url = new URL(e.request.url); 307 - const code = url.searchParams.get("code"); 308 - const state = url.searchParams.get("state"); 309 - if (code && state) { 310 - const authing = await getAuthing(state); 311 - if (authing) return e.respondWith(callback(authing, code, state)); 312 - } 305 + sw.onfetch = async (e) => 306 + e.respondWith( 307 + new Promise(async (resolve) => { 308 + const url = new URL(e.request.url); 309 + const code = url.searchParams.get("code"); 310 + const state = url.searchParams.get("state"); 311 + if (code && state) { 312 + const authing = await getAuthing(state); 313 + if (authing) return resolve(callback(authing, code, state)); 314 + } 313 315 314 - e.respondWith(authedFetch(e.request)); 315 - }; 316 + resolve(authedFetch(e.request)); 317 + }), 318 + ); 316 319 } 317 320 318 321 /**
+13 -10
example/atsw.js
··· 302 302 if (typeof ServiceWorkerGlobalScope !== "undefined" && sw instanceof ServiceWorkerGlobalScope) { 303 303 sw.oninstall = () => sw.skipWaiting(); 304 304 sw.onactivate = (e) => e.waitUntil(sw.clients.claim()); 305 - sw.onfetch = async (e) => { 306 - const url = new URL(e.request.url); 307 - const code = url.searchParams.get("code"); 308 - const state = url.searchParams.get("state"); 309 - if (code && state) { 310 - const authing = await getAuthing(state); 311 - if (authing) return e.respondWith(callback(authing, code, state)); 312 - } 305 + sw.onfetch = async (e) => 306 + e.respondWith( 307 + new Promise(async (resolve) => { 308 + const url = new URL(e.request.url); 309 + const code = url.searchParams.get("code"); 310 + const state = url.searchParams.get("state"); 311 + if (code && state) { 312 + const authing = await getAuthing(state); 313 + if (authing) return resolve(callback(authing, code, state)); 314 + } 313 315 314 - e.respondWith(authedFetch(e.request)); 315 - }; 316 + resolve(authedFetch(e.request)); 317 + }), 318 + ); 316 319 } 317 320 318 321 /**