Skip to content

Commit cf03a4f

Browse files
committed
Unregister the service worker when client_side_replay is off
If you have client_side_replay on and later turn it off, prior visitors will still have it registered in their browser until it expires unless they manually remove it through devtools or by clearing site data. While we don't expect to be regularly flipping it on and off in production, it's important to be able to roll back to the previous configuration if an issue is discovered.
1 parent 82e83af commit cf03a4f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pywb/templates/frame_insert.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@
5353
<script>
5454
window.cframe = null;
5555

56-
{% if client_side_replay %}
5756
if (navigator.serviceWorker) {
57+
{% if client_side_replay %}
5858
window.cframe = new WabacReplay("{{ wb_prefix }}", "{{ url }}", "{{ timestamp }}", "{{ static_prefix }}", "{{ coll }}", "{{ sw_prefix }}");
5959
window.cframe.init();
60-
}
60+
{% else %}
61+
navigator.serviceWorker.getRegistration("{{ sw_prefix }}").then(reg => { if (reg) reg.unregister() });
6162
{% endif %}
63+
}
6264
if (!window.cframe) {
6365
window.cframe = new ContentFrame({"url": "{{ url }}" + window.location.hash,
6466
"prefix": "{{ wb_prefix }}",

0 commit comments

Comments
 (0)