Skip to content

Commit 51cae65

Browse files
author
Manu Nair
committed
Restart clarity when page is loaded from bfcache
1 parent 532cbaa commit 51cae65

File tree

12 files changed

+98
-14
lines changed

12 files changed

+98
-14
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "0.8.47",
5+
"version": "0.8.47-beta",
66
"npmClient": "yarn"
77
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clarity",
33
"private": true,
4-
"version": "0.8.47",
4+
"version": "0.8.47-beta",
55
"repository": "https://github.com/microsoft/clarity.git",
66
"author": "Sarvesh Nagpal <sarveshn@microsoft.com>",
77
"license": "MIT",

packages/clarity-decode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clarity-decode",
3-
"version": "0.8.47",
3+
"version": "0.8.47-beta",
44
"description": "An analytics library that uses web page interactions to generate aggregated insights",
55
"author": "Microsoft Corp.",
66
"license": "MIT",
@@ -26,7 +26,7 @@
2626
"url": "https://github.com/Microsoft/clarity/issues"
2727
},
2828
"dependencies": {
29-
"clarity-js": "^0.8.47"
29+
"clarity-js": "^0.8.47-beta"
3030
},
3131
"devDependencies": {
3232
"@rollup/plugin-commonjs": "^24.0.0",

packages/clarity-devtools/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clarity-devtools",
3-
"version": "0.8.47",
3+
"version": "0.8.47-beta",
44
"private": true,
55
"description": "Adds Clarity debugging support to browser devtools",
66
"author": "Microsoft Corp.",
@@ -24,9 +24,9 @@
2424
"url": "https://github.com/Microsoft/clarity/issues"
2525
},
2626
"dependencies": {
27-
"clarity-decode": "^0.8.47",
28-
"clarity-js": "^0.8.47",
29-
"clarity-visualize": "^0.8.47"
27+
"clarity-decode": "^0.8.47-beta",
28+
"clarity-js": "^0.8.47-beta",
29+
"clarity-visualize": "^0.8.47-beta"
3030
},
3131
"devDependencies": {
3232
"@rollup/plugin-node-resolve": "^15.0.0",

packages/clarity-devtools/static/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"manifest_version": 3,
33
"name": "Microsoft Clarity Developer Tools",
44
"description": "Clarity helps you understand how users are interacting with your website.",
5-
"version": "0.8.47",
6-
"version_name": "0.8.47",
5+
"version": "0.8.47-beta",
6+
"version_name": "0.8.47-beta",
77
"minimum_chrome_version": "88",
88
"devtools_page": "devtools.html",
99
"icons": {

packages/clarity-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clarity-js",
3-
"version": "0.8.47",
3+
"version": "0.8.47-beta",
44
"description": "An analytics library that uses web page interactions to generate aggregated insights",
55
"author": "Microsoft Corp.",
66
"license": "MIT",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
let version = "0.8.47";
1+
let version = "0.8.47-beta";
22
export default version;

packages/clarity-js/src/interaction/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as timeline from "@src/interaction/timeline";
1111
import * as unload from "@src/interaction/unload";
1212
import * as visibility from "@src/interaction/visibility";
1313
import * as focus from "@src/interaction/focus";
14+
import * as pageshow from "@src/interaction/pageshow";
1415

1516
export function start(): void {
1617
timeline.start();
@@ -21,6 +22,7 @@ export function start(): void {
2122
resize.start();
2223
visibility.start();
2324
focus.start();
25+
pageshow.start();
2426
scroll.start();
2527
selection.start();
2628
change.start();
@@ -37,6 +39,7 @@ export function stop(): void {
3739
resize.stop();
3840
visibility.stop();
3941
focus.stop();
42+
pageshow.stop();
4043
scroll.stop();
4144
selection.stop();
4245
change.stop();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Constant } from "@clarity-types/core";
2+
import { Code, Severity } from "@clarity-types/data";
3+
import * as clarity from "@src/clarity";
4+
import api from "@src/core/api";
5+
import measure from "@src/core/measure";
6+
import * as internal from "@src/diagnostic/internal";
7+
8+
let bound = false;
9+
10+
export function start(): void {
11+
// Only bind once - this listener must persist even when Clarity stops
12+
// to detect when the page is restored from bfcache
13+
if (!bound) {
14+
try {
15+
window[api(Constant.AddEventListener)]("pageshow", measure(handler) as EventListener, { capture: false, passive: true });
16+
bound = true;
17+
} catch {
18+
/* do nothing */
19+
}
20+
}
21+
}
22+
23+
function handler(evt: PageTransitionEvent): void {
24+
// The persisted property indicates if the page was loaded from bfcache
25+
if (evt && evt.persisted) {
26+
// Restart Clarity since it was stopped when the page entered bfcache
27+
clarity.start();
28+
internal.log(Code.BFCache, Severity.Info);
29+
}
30+
}
31+
32+
export function stop(): void {
33+
// Intentionally don't remove the listener or reset 'bound' flag
34+
// We need the listener to persist to detect bfcache restoration
35+
}

packages/clarity-js/types/data.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export const enum Code {
212212
Config = 8,
213213
FunctionExecutionTime = 9,
214214
LeanLimit = 10,
215+
BFCache = 11,
215216
}
216217

217218
export const enum Severity {

0 commit comments

Comments
 (0)