From b8174a56188a08d44349efba3f87a1620cac4697 Mon Sep 17 00:00:00 2001 From: Tessa Walsh Date: Wed, 19 Mar 2025 12:40:09 -0400 Subject: [PATCH] Serve wabac service worker from static prefix --- pywb/apps/frontendapp.py | 2 +- pywb/static/loadWabac.js | 5 +++-- pywb/templates/frame_insert.html | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pywb/apps/frontendapp.py b/pywb/apps/frontendapp.py index 81857470..61784f47 100644 --- a/pywb/apps/frontendapp.py +++ b/pywb/apps/frontendapp.py @@ -133,7 +133,7 @@ class FrontEndApp(object): self.url_map.add(Rule('/', endpoint=self.serve_home)) if self.client_side_replay: - self.url_map.add(Rule('/static/sw.js', endpoint=self.serve_wabac_service_worker)) + self.url_map.add(Rule('/{0}/sw.js'.format(self.static_prefix), endpoint=self.serve_wabac_service_worker)) self._init_coll_routes(coll_prefix) diff --git a/pywb/static/loadWabac.js b/pywb/static/loadWabac.js index df724d25..400f6f0f 100644 --- a/pywb/static/loadWabac.js +++ b/pywb/static/loadWabac.js @@ -1,9 +1,10 @@ class WabacReplay { - constructor(prefix, url, ts) { + constructor(prefix, url, ts, staticPrefix) { this.prefix = prefix; this.url = url; this.ts = ts; + this.staticPrefix = staticPrefix; this.collName = new URL(prefix, "http://dummy").pathname.split('/')[1]; this.adblockUrl = undefined; @@ -14,7 +15,7 @@ class WabacReplay const scope = "/"; await navigator.serviceWorker.register( - "/static/sw.js?" + new URLSearchParams(this.queryParams).toString(), + `${this.staticPrefix}/sw.js?` + new URLSearchParams(this.queryParams).toString(), { scope }, ); diff --git a/pywb/templates/frame_insert.html b/pywb/templates/frame_insert.html index 8403395c..bdb0b2ee 100644 --- a/pywb/templates/frame_insert.html +++ b/pywb/templates/frame_insert.html @@ -16,7 +16,7 @@ html, body {% if client_side_replay %} {% else %}