Skip to content

Commit 18f1326

Browse files
committed
refactor frame insert to allow 'graceful fallback' to non-service worker mode, if service workers are not available,
eg. check for navigator.serviceWorker and if null, don't attempt to init sw-based path
1 parent f5162d2 commit 18f1326

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

pywb/static/loadWabac.js

-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ class WabacReplay
7676
}
7777
});
7878

79-
window.cframe = this;
80-
8179
if (inited) {
8280
await inited;
8381
}

pywb/templates/frame_insert.html

+12-9
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313

1414
</style>
1515

16+
<script src='{{ static_prefix }}/wb_frame.js'> </script>
1617
{% if client_side_replay %}
1718
<script src='{{ static_prefix }}/loadWabac.js'></script>
18-
<script>
19-
new WabacReplay("{{ wb_prefix }}", "{{ url }}", "{{ timestamp }}", "{{ static_prefix }}", "{{ coll }}", "{{ sw_prefix }}").init();
20-
</script>
21-
{% else %}
22-
<script src='{{ static_prefix }}/wb_frame.js'> </script>
2319
{% endif %}
2420

2521
{% autoescape false %}
@@ -54,15 +50,22 @@
5450
<iframe id="replay_iframe" frameborder="0" seamless="seamless" scrolling="yes" class="wb_iframe" allow="autoplay; fullscreen"></iframe>
5551
</div>
5652

57-
{% if not client_side_replay %}
5853
<script>
59-
var cframe = new ContentFrame({"url": "{{ url }}" + window.location.hash,
54+
window.cframe = null;
55+
56+
{% if client_side_replay %}
57+
if (navigator.serviceWorker) {
58+
window.cframe = new WabacReplay("{{ wb_prefix }}", "{{ url }}", "{{ timestamp }}", "{{ static_prefix }}", "{{ coll }}", "{{ sw_prefix }}");
59+
window.cframe.init();
60+
}
61+
{% endif %}
62+
if (!window.cframe) {
63+
window.cframe = new ContentFrame({"url": "{{ url }}" + window.location.hash,
6064
"prefix": "{{ wb_prefix }}",
6165
"request_ts": "{{ wb_url.timestamp }}",
6266
"iframe": "#replay_iframe"});
63-
67+
}
6468
</script>
65-
{% endif %}
6669
</body>
6770
</html>
6871
{% endautoescape %}

0 commit comments

Comments
 (0)