Skip to content

Commit

Permalink
fs serviceworker debug support
Browse files Browse the repository at this point in the history
  • Loading branch information
hrgdavor committed Apr 23, 2024
1 parent 2b1f80f commit fab2294
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/fs-serviceworker/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# TODO
- explain debug url parameter

# fs-serviceworker

ServiceWorker that returns files filleld in cache by `fs-provider`. You can use it as-is or extend and customize.
Expand Down
6 changes: 4 additions & 2 deletions packages/fs-serviceworker/fs-serviceworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { messageProxy } from '@jscadui/postmessage'

const version = 'SW7'
const clientMap = {}
let prefix = new URL(location.toString()).searchParams.get('prefix')
const searchParams = new URL(location.toString()).searchParams
let prefix = searchParams.get('prefix')
let initPath = prefix + 'init'
let debug = searchParams.get('debug')

self.addEventListener('activate', event => {
event.waitUntil(clients.claim())
Expand All @@ -27,7 +29,7 @@ self.addEventListener('install', event => {
const getClientWrapper = async clientId => {
let clientWrapper = clientMap[clientId]
if (!clientWrapper) {
clientWrapper = clientMap[clientId] = { api: messageProxy(await clients.get(clientId), {}, { debug: 'SW::' }) }
clientWrapper = clientMap[clientId] = { api: messageProxy(await clients.get(clientId), {}, { debug }) }
clientWrapper.cache = await caches.open(prefix + clientId)
}
return clientWrapper
Expand Down

0 comments on commit fab2294

Please sign in to comment.