@aj-2000-test/goodlogs-sdk 0.3.2 → 0.3.3
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/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/replay.cjs +1 -1
- package/dist/replay.d.cts +25 -22
- package/dist/replay.d.ts +25 -22
- package/dist/replay.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var S=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var I={us:"https://goodlogs-api-us.happyhill-a7c56143.centralindia.azurecontainerapps.io",eu:"https://goodlogs-api-eu.yellowmeadow-422296f6.japaneast.azurecontainerapps.io",ap:"https://goodlogs-api-ap.delightfulsand-90b72c09.southeastasia.azurecontainerapps.io"};function B(o){let t=o.split("_");return t.length>=4&&t[0]==="gl"?t[2]:"eu"}function y(o,t){if(t)return t;let e=B(o);return I[e]||I.eu}var G=5e3,F=50,v="0.3.
|
|
1
|
+
'use strict';var S=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var I={us:"https://goodlogs-api-us.happyhill-a7c56143.centralindia.azurecontainerapps.io",eu:"https://goodlogs-api-eu.yellowmeadow-422296f6.japaneast.azurecontainerapps.io",ap:"https://goodlogs-api-ap.delightfulsand-90b72c09.southeastasia.azurecontainerapps.io"};function B(o){let t=o.split("_");return t.length>=4&&t[0]==="gl"?t[2]:"eu"}function y(o,t){if(t)return t;let e=B(o);return I[e]||I.eu}var G=5e3,F=50,v="0.3.3",w="gl_anon_id",_="gl_session_id";function b(){return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,o=>{let t=Math.random()*16|0;return (o==="x"?t:t&3|8).toString(16)})}function M(){let o={$goodlogs_sdk:"js",$goodlogs_sdk_version:v};return typeof navigator>"u"||(typeof screen<"u"&&(o.$screen=`${screen.width}x${screen.height}`),typeof navigator<"u"&&(o.$language=navigator.language??""),typeof location<"u"&&(o.$url=location.href,o.$path=location.pathname,o.$page=location.pathname.split("/").filter(Boolean).pop()||"/"),typeof document<"u"&&(document.referrer&&(o.$referrer=document.referrer),document.title&&(o.$title=document.title))),o}function U(o,t){let e={$session_id:o,$distinct_id:t,$goodlogs_sdk:"js",$goodlogs_sdk_version:v};return typeof navigator>"u"||typeof location<"u"&&(e.$url=location.href,e.$path=location.pathname),e}function D(){if(!(typeof document<"u"))try{let t=new Error().stack?.split(`
|
|
2
2
|
`);if(!t)return;for(let e=3;e<Math.min(t.length,8);e++){let n=t[e]?.trim();if(!n||n.includes("goodlogs")&&(n.includes("client.")||n.includes("index.")))continue;let r=n.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):\d+\)?/);if(r){let s=r[1]||"<anonymous>",i=r[2]?.replace(/^.*[/\\]/,"")??"",d=r[3];return `${s}@${i}:${d}`}}}catch{}}function K(){if(typeof localStorage<"u"){let o=localStorage.getItem(w);if(o)return o;let t=b();return localStorage.setItem(w,t),t}return b()}function X(){if(typeof sessionStorage<"u"){let o=sessionStorage.getItem(_);if(o)return o;let t=b();return sessionStorage.setItem(_,t),t}return b()}function z(){let o="";for(let t=0;t<32;t++)o+=(Math.random()*16|0).toString(16);return o}function V(){let o="";for(let t=0;t<16;t++)o+=(Math.random()*16|0).toString(16);return o}function W(o,t){switch(o){case "lcp":return t<=2500?"good":t<=4e3?"needs-improvement":"poor";case "inp":return t<=200?"good":t<=500?"needs-improvement":"poor";case "cls":return t<=.1?"good":t<=.25?"needs-improvement":"poor";case "fcp":return t<=1800?"good":t<=3e3?"needs-improvement":"poor";case "ttfb":return t<=800?"good":t<=1800?"needs-improvement":"poor";default:return}}function J(o){if(!o)return [];let t=[];for(let e of o.split(`
|
|
3
3
|
`)){let n=e.trim();if(!n||n.startsWith("Error")||n.startsWith("at Error"))continue;let r=/^at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/.exec(n);if(r){let s=r[1]?.trim(),i=r[2];t.push({function:s&&s!=="<anonymous>"?s:void 0,filename:i,lineno:Number(r[3]),colno:Number(r[4]),abs_path:i,in_app:!i.includes("node_modules/")&&!i.includes("/dist/")&&!i.startsWith("internal/")});continue}if(r=/^([^@]*)@(.+?):(\d+):(\d+)$/.exec(n),r){let s=r[1]?.trim(),i=r[2];t.push({function:s||void 0,filename:i,lineno:Number(r[3]),colno:Number(r[4]),abs_path:i,in_app:!i.includes("node_modules/")&&!i.includes("/dist/")});}}return t}var R=class R{constructor(t){this.originalFetch=null;this.xhrPatched=false;this.logBuffer=[];this.eventBuffer=[];this.errorBuffer=[];this.vitalBuffer=[];this.spanBuffer=[];this.breadcrumbBuffer=[];this.timer=null;this.visibilityHandler=null;this.clickHandler=null;this.lastPath="";this.navTransaction=null;this.errorHandler=null;this.rejectionHandler=null;this.apiKey=t.apiKey,this.endpoint=y(t.apiKey,t.endpoint).replace(/\/+$/,""),this.flushInterval=t.flushInterval??G,this.batchSize=t.batchSize??F,this.defaultContext=t.defaultContext??{},this.onError=t.onError??(()=>{}),this.disabled=t.disabled??false,this.telemetry=t.telemetry??true,this.useEnvelope=t.useEnvelope??false,this.autoFetch=t.autoFetch??(this.useEnvelope&&t.autocapture!==false),this.anonymousId=K(),this.sessionId=X(),this.disabled&&typeof console<"u"&&console.warn("[GoodLogs] SDK is disabled. No events or logs will be sent."),this.disabled||(this.startTimer(),this.attachPageLifecycle(),t.autocapture!==false&&(this.attachClickCapture(),this.captureWebVitals(),this.attachPageviewCapture(),this.attachGlobalErrorHandlers()),this.autoFetch&&(this.attachFetchInstrumentation(),this.attachXhrInstrumentation()),this.sendTelemetry("init","info"));}log(t,e,n){if(this.disabled)return;let r=65536,s=e;e.length>r&&(s=e.slice(0,r-100)+`
|
|
4
4
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var S=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var I={us:"https://goodlogs-api-us.happyhill-a7c56143.centralindia.azurecontainerapps.io",eu:"https://goodlogs-api-eu.yellowmeadow-422296f6.japaneast.azurecontainerapps.io",ap:"https://goodlogs-api-ap.delightfulsand-90b72c09.southeastasia.azurecontainerapps.io"};function B(o){let t=o.split("_");return t.length>=4&&t[0]==="gl"?t[2]:"eu"}function y(o,t){if(t)return t;let e=B(o);return I[e]||I.eu}var G=5e3,F=50,v="0.3.
|
|
1
|
+
var S=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var I={us:"https://goodlogs-api-us.happyhill-a7c56143.centralindia.azurecontainerapps.io",eu:"https://goodlogs-api-eu.yellowmeadow-422296f6.japaneast.azurecontainerapps.io",ap:"https://goodlogs-api-ap.delightfulsand-90b72c09.southeastasia.azurecontainerapps.io"};function B(o){let t=o.split("_");return t.length>=4&&t[0]==="gl"?t[2]:"eu"}function y(o,t){if(t)return t;let e=B(o);return I[e]||I.eu}var G=5e3,F=50,v="0.3.3",w="gl_anon_id",_="gl_session_id";function b(){return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,o=>{let t=Math.random()*16|0;return (o==="x"?t:t&3|8).toString(16)})}function M(){let o={$goodlogs_sdk:"js",$goodlogs_sdk_version:v};return typeof navigator>"u"||(typeof screen<"u"&&(o.$screen=`${screen.width}x${screen.height}`),typeof navigator<"u"&&(o.$language=navigator.language??""),typeof location<"u"&&(o.$url=location.href,o.$path=location.pathname,o.$page=location.pathname.split("/").filter(Boolean).pop()||"/"),typeof document<"u"&&(document.referrer&&(o.$referrer=document.referrer),document.title&&(o.$title=document.title))),o}function U(o,t){let e={$session_id:o,$distinct_id:t,$goodlogs_sdk:"js",$goodlogs_sdk_version:v};return typeof navigator>"u"||typeof location<"u"&&(e.$url=location.href,e.$path=location.pathname),e}function D(){if(!(typeof document<"u"))try{let t=new Error().stack?.split(`
|
|
2
2
|
`);if(!t)return;for(let e=3;e<Math.min(t.length,8);e++){let n=t[e]?.trim();if(!n||n.includes("goodlogs")&&(n.includes("client.")||n.includes("index.")))continue;let r=n.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):\d+\)?/);if(r){let s=r[1]||"<anonymous>",i=r[2]?.replace(/^.*[/\\]/,"")??"",d=r[3];return `${s}@${i}:${d}`}}}catch{}}function K(){if(typeof localStorage<"u"){let o=localStorage.getItem(w);if(o)return o;let t=b();return localStorage.setItem(w,t),t}return b()}function X(){if(typeof sessionStorage<"u"){let o=sessionStorage.getItem(_);if(o)return o;let t=b();return sessionStorage.setItem(_,t),t}return b()}function z(){let o="";for(let t=0;t<32;t++)o+=(Math.random()*16|0).toString(16);return o}function V(){let o="";for(let t=0;t<16;t++)o+=(Math.random()*16|0).toString(16);return o}function W(o,t){switch(o){case "lcp":return t<=2500?"good":t<=4e3?"needs-improvement":"poor";case "inp":return t<=200?"good":t<=500?"needs-improvement":"poor";case "cls":return t<=.1?"good":t<=.25?"needs-improvement":"poor";case "fcp":return t<=1800?"good":t<=3e3?"needs-improvement":"poor";case "ttfb":return t<=800?"good":t<=1800?"needs-improvement":"poor";default:return}}function J(o){if(!o)return [];let t=[];for(let e of o.split(`
|
|
3
3
|
`)){let n=e.trim();if(!n||n.startsWith("Error")||n.startsWith("at Error"))continue;let r=/^at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/.exec(n);if(r){let s=r[1]?.trim(),i=r[2];t.push({function:s&&s!=="<anonymous>"?s:void 0,filename:i,lineno:Number(r[3]),colno:Number(r[4]),abs_path:i,in_app:!i.includes("node_modules/")&&!i.includes("/dist/")&&!i.startsWith("internal/")});continue}if(r=/^([^@]*)@(.+?):(\d+):(\d+)$/.exec(n),r){let s=r[1]?.trim(),i=r[2];t.push({function:s||void 0,filename:i,lineno:Number(r[3]),colno:Number(r[4]),abs_path:i,in_app:!i.includes("node_modules/")&&!i.includes("/dist/")});}}return t}var R=class R{constructor(t){this.originalFetch=null;this.xhrPatched=false;this.logBuffer=[];this.eventBuffer=[];this.errorBuffer=[];this.vitalBuffer=[];this.spanBuffer=[];this.breadcrumbBuffer=[];this.timer=null;this.visibilityHandler=null;this.clickHandler=null;this.lastPath="";this.navTransaction=null;this.errorHandler=null;this.rejectionHandler=null;this.apiKey=t.apiKey,this.endpoint=y(t.apiKey,t.endpoint).replace(/\/+$/,""),this.flushInterval=t.flushInterval??G,this.batchSize=t.batchSize??F,this.defaultContext=t.defaultContext??{},this.onError=t.onError??(()=>{}),this.disabled=t.disabled??false,this.telemetry=t.telemetry??true,this.useEnvelope=t.useEnvelope??false,this.autoFetch=t.autoFetch??(this.useEnvelope&&t.autocapture!==false),this.anonymousId=K(),this.sessionId=X(),this.disabled&&typeof console<"u"&&console.warn("[GoodLogs] SDK is disabled. No events or logs will be sent."),this.disabled||(this.startTimer(),this.attachPageLifecycle(),t.autocapture!==false&&(this.attachClickCapture(),this.captureWebVitals(),this.attachPageviewCapture(),this.attachGlobalErrorHandlers()),this.autoFetch&&(this.attachFetchInstrumentation(),this.attachXhrInstrumentation()),this.sendTelemetry("init","info"));}log(t,e,n){if(this.disabled)return;let r=65536,s=e;e.length>r&&(s=e.slice(0,r-100)+`
|
|
4
4
|
|
package/dist/replay.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';async function
|
|
1
|
+
'use strict';var _=new Set([1,3,6]);function H(n){return n.every(e=>{if(e.type!==3)return false;let o=e.data?.source;return o!==void 0&&_.has(o)})}var m=null;async function K(n,e={}){if(typeof document>"u")return null;if(m)return m;let o=e.sampleRate??1;if(o<1&&Math.random()>o)return null;let a=e.rrwebRecord??await j();if(!a)return null;let r=n.endpoint,l=n.apiKey,i=n.sessionId,R=n.getDistinctId(),I=e.flushIntervalMs??5e3,E=e.flushBytes??5e5,T=e.sessionTimeoutMs??1800*1e3,B=e.maxSessionMs??3600*1e3,d=[],f=0,C=0,g=false,p=false,b=Date.now(),O=Date.now();u(r,l,{session_id:i,distinct_id:R,start_url:typeof location<"u"?location.href:null,last_url:typeof location<"u"?location.href:null},e.onError);let c=async(t=false)=>{if(d.length===0)return;if(!t&&H(d)){d=[],f=0;return}let s=d,$=s[0].timestamp,S=s[s.length-1].timestamp,z=s.length;d=[],f=0;let U=C++;try{let w=JSON.stringify(s),G=await N(w),q=`${r}/v1/replay/chunks?session_id=${encodeURIComponent(i)}&seq=${U}&start_ts=${encodeURIComponent(new Date($).toISOString())}&end_ts=${encodeURIComponent(new Date(S).toISOString())}&event_count=${z}`;await fetch(q,{method:"POST",headers:{Authorization:`Bearer ${l}`,"Content-Type":"application/gzip","Content-Encoding":"gzip"},body:G,keepalive:!0});}catch(w){e.onError?.(w);}u(r,l,{session_id:i,last_url:typeof location<"u"?location.href:null,last_activity_at:new Date(S).toISOString(),has_error:g||void 0},e.onError);},v=t=>{if(!p){p=true,clearInterval(x),clearInterval(A),document?.removeEventListener("visibilitychange",y),typeof window<"u"&&window.removeEventListener("beforeunload",h);try{D();}catch(s){e.onError?.(s);}c(true),u(r,l,{session_id:i,ended_at:new Date().toISOString()},e.onError),m=null;}},D=a({emit:t=>{if(p)return;t.type===3&&_.has(t.data?.source??-1)||(b=Date.now()),d.push(t),f+=256,f>=E&&c();},checkoutEveryNms:6e4,maskAllInputs:e.maskAllInputs??true,blockSelector:e.blockSelector??"[data-gl-block]",maskTextSelector:e.maskTextSelector??"[data-gl-mask]",sampling:{mousemove:50,mouseInteraction:true,scroll:150,input:"last"}}),x=setInterval(()=>{c();},I),A=setInterval(()=>{let t=Date.now();if(t-b>T){v();return}if(t-O>B){v();return}},1e4),y=()=>{document?.visibilityState==="hidden"&&(c(true),u(r,l,{session_id:i,ended_at:new Date().toISOString()},e.onError));};document.addEventListener("visibilitychange",y);let h=()=>{c(true),u(r,l,{session_id:i,ended_at:new Date().toISOString()},e.onError);};typeof window<"u"&&window.addEventListener("beforeunload",h);let L=setInterval(()=>{globalThis.__gl_replay_has_error__&&(g=true);},1e3),M=v,P=t=>{clearInterval(L),M();},k={sessionId:i,flush:()=>c(true),stop:()=>P()};return m=k,k}async function u(n,e,o,a){try{await fetch(`${n}/v1/replay/sessions`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(o),keepalive:!0});}catch(r){a?.(r);}}async function N(n){if(typeof CompressionStream>"u"||typeof Blob>"u"||typeof Response>"u")return n;let o=new Blob([n]).stream().pipeThrough(new CompressionStream("gzip")),a=await new Response(o).arrayBuffer();return new Blob([a],{type:"application/gzip"})}async function j(){try{let n=await import('rrweb');return n.record??n.default?.record??null}catch{return null}}exports.startReplay=K;
|
package/dist/replay.d.cts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { G as GoodLogs } from './client-w3t1Yzjd.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Session Replay (rrweb) — optional,
|
|
4
|
+
* Session Replay (rrweb) — optional, tree-split.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Industry-standard behaviours (Sentry/PostHog parity):
|
|
7
|
+
* 1. 30-min inactivity timeout → seals session, new ID on resume.
|
|
8
|
+
* 2. Idle suppression: if the queue contains only mouse-move / scroll
|
|
9
|
+
* events and nothing visual changed, skip the flush entirely.
|
|
10
|
+
* 3. Auto-end on visibilitychange=hidden + beforeunload (keepalive).
|
|
11
|
+
* 4. Dedup guard: calling startReplay() twice is a no-op.
|
|
12
|
+
* 5. Max session duration: 60 min hard cap → auto-stop.
|
|
13
|
+
* 6. rrweb sampling: mouse movement 50ms, scroll 150ms to cut volume.
|
|
9
14
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Capture is *not* a video — it's the rrweb DOM-mutation stream gzipped
|
|
14
|
-
* and shipped to /v1/replay/chunks. See docs/storage-design.md for storage.
|
|
15
|
-
*
|
|
16
|
-
* rrweb is a real npm dep, dynamically imported so the core SDK bundle
|
|
17
|
-
* stays small and the rrweb code only loads when replay is started.
|
|
15
|
+
* rrweb is a real npm peer dep, dynamically imported so the core SDK
|
|
16
|
+
* bundle stays small and the rrweb code only loads when replay is started.
|
|
18
17
|
*/
|
|
19
18
|
|
|
20
19
|
interface RrwebRecord {
|
|
@@ -37,21 +36,25 @@ interface RrwebEvent {
|
|
|
37
36
|
timestamp: number;
|
|
38
37
|
}
|
|
39
38
|
interface ReplayOptions {
|
|
40
|
-
/** Provide rrweb
|
|
39
|
+
/** Provide rrweb `record` yourself (bundled). Skips dynamic import. */
|
|
41
40
|
rrwebRecord?: RrwebRecord;
|
|
42
|
-
/** Flush
|
|
41
|
+
/** Flush interval ms (default 5000). */
|
|
43
42
|
flushIntervalMs?: number;
|
|
44
|
-
/**
|
|
43
|
+
/** Flush when queue reaches this byte estimate (default 500_000). */
|
|
45
44
|
flushBytes?: number;
|
|
46
|
-
/** Sample rate 0..1 (default 1
|
|
45
|
+
/** Sample rate 0..1 (default 1). */
|
|
47
46
|
sampleRate?: number;
|
|
48
|
-
/** Block
|
|
47
|
+
/** Block elements matching this CSS selector. */
|
|
49
48
|
blockSelector?: string;
|
|
50
|
-
/** Mask text
|
|
49
|
+
/** Mask text in elements matching this selector. */
|
|
51
50
|
maskTextSelector?: string;
|
|
52
|
-
/** Mask all
|
|
51
|
+
/** Mask all inputs/textareas (default true). */
|
|
53
52
|
maskAllInputs?: boolean;
|
|
54
|
-
/**
|
|
53
|
+
/** Inactivity timeout ms before session auto-seals (default 30 min). */
|
|
54
|
+
sessionTimeoutMs?: number;
|
|
55
|
+
/** Hard cap session length ms (default 60 min). */
|
|
56
|
+
maxSessionMs?: number;
|
|
57
|
+
/** Error callback. */
|
|
55
58
|
onError?: (e: unknown) => void;
|
|
56
59
|
}
|
|
57
60
|
interface ReplayHandle {
|
|
@@ -61,8 +64,8 @@ interface ReplayHandle {
|
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
66
|
* Start recording. Returns a handle with `stop()` and `flush()`.
|
|
64
|
-
*
|
|
67
|
+
* Second call is a no-op — returns the existing handle.
|
|
65
68
|
*/
|
|
66
69
|
declare function startReplay(gl: GoodLogs, options?: ReplayOptions): Promise<ReplayHandle | null>;
|
|
67
70
|
|
|
68
|
-
export { type ReplayOptions, type RrwebEvent, startReplay };
|
|
71
|
+
export { type ReplayHandle, type ReplayOptions, type RrwebEvent, startReplay };
|
package/dist/replay.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { G as GoodLogs } from './client-w3t1Yzjd.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Session Replay (rrweb) — optional,
|
|
4
|
+
* Session Replay (rrweb) — optional, tree-split.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Industry-standard behaviours (Sentry/PostHog parity):
|
|
7
|
+
* 1. 30-min inactivity timeout → seals session, new ID on resume.
|
|
8
|
+
* 2. Idle suppression: if the queue contains only mouse-move / scroll
|
|
9
|
+
* events and nothing visual changed, skip the flush entirely.
|
|
10
|
+
* 3. Auto-end on visibilitychange=hidden + beforeunload (keepalive).
|
|
11
|
+
* 4. Dedup guard: calling startReplay() twice is a no-op.
|
|
12
|
+
* 5. Max session duration: 60 min hard cap → auto-stop.
|
|
13
|
+
* 6. rrweb sampling: mouse movement 50ms, scroll 150ms to cut volume.
|
|
9
14
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Capture is *not* a video — it's the rrweb DOM-mutation stream gzipped
|
|
14
|
-
* and shipped to /v1/replay/chunks. See docs/storage-design.md for storage.
|
|
15
|
-
*
|
|
16
|
-
* rrweb is a real npm dep, dynamically imported so the core SDK bundle
|
|
17
|
-
* stays small and the rrweb code only loads when replay is started.
|
|
15
|
+
* rrweb is a real npm peer dep, dynamically imported so the core SDK
|
|
16
|
+
* bundle stays small and the rrweb code only loads when replay is started.
|
|
18
17
|
*/
|
|
19
18
|
|
|
20
19
|
interface RrwebRecord {
|
|
@@ -37,21 +36,25 @@ interface RrwebEvent {
|
|
|
37
36
|
timestamp: number;
|
|
38
37
|
}
|
|
39
38
|
interface ReplayOptions {
|
|
40
|
-
/** Provide rrweb
|
|
39
|
+
/** Provide rrweb `record` yourself (bundled). Skips dynamic import. */
|
|
41
40
|
rrwebRecord?: RrwebRecord;
|
|
42
|
-
/** Flush
|
|
41
|
+
/** Flush interval ms (default 5000). */
|
|
43
42
|
flushIntervalMs?: number;
|
|
44
|
-
/**
|
|
43
|
+
/** Flush when queue reaches this byte estimate (default 500_000). */
|
|
45
44
|
flushBytes?: number;
|
|
46
|
-
/** Sample rate 0..1 (default 1
|
|
45
|
+
/** Sample rate 0..1 (default 1). */
|
|
47
46
|
sampleRate?: number;
|
|
48
|
-
/** Block
|
|
47
|
+
/** Block elements matching this CSS selector. */
|
|
49
48
|
blockSelector?: string;
|
|
50
|
-
/** Mask text
|
|
49
|
+
/** Mask text in elements matching this selector. */
|
|
51
50
|
maskTextSelector?: string;
|
|
52
|
-
/** Mask all
|
|
51
|
+
/** Mask all inputs/textareas (default true). */
|
|
53
52
|
maskAllInputs?: boolean;
|
|
54
|
-
/**
|
|
53
|
+
/** Inactivity timeout ms before session auto-seals (default 30 min). */
|
|
54
|
+
sessionTimeoutMs?: number;
|
|
55
|
+
/** Hard cap session length ms (default 60 min). */
|
|
56
|
+
maxSessionMs?: number;
|
|
57
|
+
/** Error callback. */
|
|
55
58
|
onError?: (e: unknown) => void;
|
|
56
59
|
}
|
|
57
60
|
interface ReplayHandle {
|
|
@@ -61,8 +64,8 @@ interface ReplayHandle {
|
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
66
|
* Start recording. Returns a handle with `stop()` and `flush()`.
|
|
64
|
-
*
|
|
67
|
+
* Second call is a no-op — returns the existing handle.
|
|
65
68
|
*/
|
|
66
69
|
declare function startReplay(gl: GoodLogs, options?: ReplayOptions): Promise<ReplayHandle | null>;
|
|
67
70
|
|
|
68
|
-
export { type ReplayOptions, type RrwebEvent, startReplay };
|
|
71
|
+
export { type ReplayHandle, type ReplayOptions, type RrwebEvent, startReplay };
|
package/dist/replay.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
async function
|
|
1
|
+
var _=new Set([1,3,6]);function H(n){return n.every(e=>{if(e.type!==3)return false;let o=e.data?.source;return o!==void 0&&_.has(o)})}var m=null;async function K(n,e={}){if(typeof document>"u")return null;if(m)return m;let o=e.sampleRate??1;if(o<1&&Math.random()>o)return null;let a=e.rrwebRecord??await j();if(!a)return null;let r=n.endpoint,l=n.apiKey,i=n.sessionId,R=n.getDistinctId(),I=e.flushIntervalMs??5e3,E=e.flushBytes??5e5,T=e.sessionTimeoutMs??1800*1e3,B=e.maxSessionMs??3600*1e3,d=[],f=0,C=0,g=false,p=false,b=Date.now(),O=Date.now();u(r,l,{session_id:i,distinct_id:R,start_url:typeof location<"u"?location.href:null,last_url:typeof location<"u"?location.href:null},e.onError);let c=async(t=false)=>{if(d.length===0)return;if(!t&&H(d)){d=[],f=0;return}let s=d,$=s[0].timestamp,S=s[s.length-1].timestamp,z=s.length;d=[],f=0;let U=C++;try{let w=JSON.stringify(s),G=await N(w),q=`${r}/v1/replay/chunks?session_id=${encodeURIComponent(i)}&seq=${U}&start_ts=${encodeURIComponent(new Date($).toISOString())}&end_ts=${encodeURIComponent(new Date(S).toISOString())}&event_count=${z}`;await fetch(q,{method:"POST",headers:{Authorization:`Bearer ${l}`,"Content-Type":"application/gzip","Content-Encoding":"gzip"},body:G,keepalive:!0});}catch(w){e.onError?.(w);}u(r,l,{session_id:i,last_url:typeof location<"u"?location.href:null,last_activity_at:new Date(S).toISOString(),has_error:g||void 0},e.onError);},v=t=>{if(!p){p=true,clearInterval(x),clearInterval(A),document?.removeEventListener("visibilitychange",y),typeof window<"u"&&window.removeEventListener("beforeunload",h);try{D();}catch(s){e.onError?.(s);}c(true),u(r,l,{session_id:i,ended_at:new Date().toISOString()},e.onError),m=null;}},D=a({emit:t=>{if(p)return;t.type===3&&_.has(t.data?.source??-1)||(b=Date.now()),d.push(t),f+=256,f>=E&&c();},checkoutEveryNms:6e4,maskAllInputs:e.maskAllInputs??true,blockSelector:e.blockSelector??"[data-gl-block]",maskTextSelector:e.maskTextSelector??"[data-gl-mask]",sampling:{mousemove:50,mouseInteraction:true,scroll:150,input:"last"}}),x=setInterval(()=>{c();},I),A=setInterval(()=>{let t=Date.now();if(t-b>T){v();return}if(t-O>B){v();return}},1e4),y=()=>{document?.visibilityState==="hidden"&&(c(true),u(r,l,{session_id:i,ended_at:new Date().toISOString()},e.onError));};document.addEventListener("visibilitychange",y);let h=()=>{c(true),u(r,l,{session_id:i,ended_at:new Date().toISOString()},e.onError);};typeof window<"u"&&window.addEventListener("beforeunload",h);let L=setInterval(()=>{globalThis.__gl_replay_has_error__&&(g=true);},1e3),M=v,P=t=>{clearInterval(L),M();},k={sessionId:i,flush:()=>c(true),stop:()=>P()};return m=k,k}async function u(n,e,o,a){try{await fetch(`${n}/v1/replay/sessions`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(o),keepalive:!0});}catch(r){a?.(r);}}async function N(n){if(typeof CompressionStream>"u"||typeof Blob>"u"||typeof Response>"u")return n;let o=new Blob([n]).stream().pipeThrough(new CompressionStream("gzip")),a=await new Response(o).arrayBuffer();return new Blob([a],{type:"application/gzip"})}async function j(){try{let n=await import('rrweb');return n.record??n.default?.record??null}catch{return null}}export{K as startReplay};
|