@3cr/viewer-browser 0.0.150 → 0.0.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.html CHANGED
@@ -23,12 +23,15 @@
23
23
  { userID: undefined },
24
24
  {environment: {tier: 'production'}}
25
25
  );
26
+
27
+ const replayer = new SessionReplay(client);
28
+ console.log(replayer)
29
+
26
30
  runStatsigAutoCapture(client);
27
31
  window.playgroundStatsigClient = client
28
32
  runStatsigSessionReplay(client);
29
33
 
30
- const replayer = new SessionReplay(client);
31
- console.log(replayer)
34
+
32
35
 
33
36
  const dynamicConfig = window.playgroundStatsigClient.getDynamicConfig("3cr_viewer_version");
34
37
  const version = dynamicConfig.value["sdkVersion"] ?? "1.0.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3cr/viewer-browser",
3
- "version": "0.0.150",
3
+ "version": "0.0.152",
4
4
  "main": "./dist/Viewer3CR.umd.js",
5
5
  "module": "dist/Viewer3CR.umd.js",
6
6
  "homepage": "https://docs.3cr.singular.health",
@@ -7,6 +7,12 @@
7
7
  <link rel="preconnect" href="https://fonts.googleapis.com" />
8
8
  <script src="https://cdn.jsdelivr.net/npm/@3cr/viewer-browser@{{version}}/dist/Viewer3CR.umd.js"> </script>
9
9
  <script type="module">
10
+ function invokeServiceWorkerUpdateFlow(registration) {
11
+ if (registration.waiting) {
12
+ // let waiting Service Worker know it should became active
13
+ registration.waiting.postMessage('SKIP_WAITING')
14
+ }
15
+ }
10
16
  function initServiceWorker() {
11
17
  // Only enable service worker in production
12
18
  if ("serviceWorker" in navigator) {
@@ -17,10 +23,44 @@
17
23
  "[CHECK]: Service_Worker_Registered_With_Scope",
18
24
  registration.scope
19
25
  );
26
+ // ensure the case when the updatefound event was missed is also handled
27
+ // by re-invoking the prompt when there's a waiting Service Worker
28
+ if (registration.waiting) {
29
+ invokeServiceWorkerUpdateFlow(registration)
30
+ }
31
+
32
+ // detect Service Worker update available and wait for it to become installed
33
+ registration.addEventListener('updatefound', () => {
34
+ if (registration.installing) {
35
+ // wait until the new Service worker is actually installed (ready to take over)
36
+ registration.installing.addEventListener('statechange', () => {
37
+ if (registration.waiting) {
38
+ // if there's an existing controller (previous Service Worker), show the prompt
39
+ if (navigator.serviceWorker.controller) {
40
+ invokeServiceWorkerUpdateFlow(registration)
41
+ } else {
42
+ // otherwise it's the first install, nothing to do
43
+ console.log('Service Worker initialized for the first time')
44
+ }
45
+ }
46
+ })
47
+ }
48
+ })
49
+
50
+ let refreshing = false;
51
+
52
+ // detect controller change and refresh the page
53
+ navigator.serviceWorker.addEventListener('controllerchange', () => {
54
+ if (!refreshing) {
55
+ window.location.reload()
56
+ refreshing = true
57
+ }
58
+ })
20
59
  })
21
60
  .catch((error) => {
22
61
  console.error("[ERR]: Service_Worker_Registration_Failed:", error);
23
62
  });
63
+
24
64
  }
25
65
  }
26
66
 
@@ -47,6 +87,8 @@
47
87
  { userID: undefined },
48
88
  {environment: {tier: 'production'}}
49
89
  );
90
+ const replayer = new SessionReplay(client);
91
+ console.log(replayer)
50
92
  runStatsigAutoCapture(client);
51
93
  window.playgroundStatsigClient = client
52
94
  runStatsigSessionReplay(client);
@@ -54,8 +96,7 @@
54
96
  const dynamicConfig = window.playgroundStatsigClient.getDynamicConfig("3cr_viewer_version");
55
97
  const version = dynamicConfig.value["sdkVersion"] ?? "1.0.0";
56
98
 
57
- const replayer = new SessionReplay(client);
58
- console.log(replayer)
99
+
59
100
 
60
101
 
61
102
  client.initializeAsync().then(() => {
package/playground/sw.js CHANGED
@@ -1,3 +1,18 @@
1
+ // Service Worker-based solution
2
+ self.addEventListener("activate", async () => {
3
+ // after we've taken over, iterate over all the current clients (windows)
4
+ const tabs = await self.clients.matchAll({ type: "window" });
5
+ tabs.forEach((tab) => {
6
+ // ...and refresh each one of them
7
+ tab.navigate(tab.url);
8
+ });
9
+ });
10
+
11
+ self.addEventListener("message", (event) => {
12
+ if (event.data === "SKIP_WAITING") {
13
+ self.skipWaiting().then((r) => {});
14
+ }
15
+ });
1
16
  self.addEventListener("fetch", (event) => {
2
17
  event.respondWith(handleServerRequest(event.request));
3
18
  });