@devskin/browser-sdk 1.0.31 → 1.0.32

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.
@@ -4,6 +4,38 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DevSkin = factory());
5
5
  })(this, (function () { 'use strict';
6
6
 
7
+ /******************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
+
23
+
24
+ function __awaiter$1(thisArg, _arguments, P, generator) {
25
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
+ return new (P || (P = Promise))(function (resolve, reject) {
27
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
31
+ });
32
+ }
33
+
34
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
+ var e = new Error(message);
36
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
+ };
38
+
7
39
  class DeviceCollector {
8
40
  constructor(config) {
9
41
  this.config = config;
@@ -121,38 +153,6 @@
121
153
  }
122
154
  }
123
155
 
124
- /******************************************************************************
125
- Copyright (c) Microsoft Corporation.
126
-
127
- Permission to use, copy, modify, and/or distribute this software for any
128
- purpose with or without fee is hereby granted.
129
-
130
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
131
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
132
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
133
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
134
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
135
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
136
- PERFORMANCE OF THIS SOFTWARE.
137
- ***************************************************************************** */
138
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
139
-
140
-
141
- function __awaiter$1(thisArg, _arguments, P, generator) {
142
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
143
- return new (P || (P = Promise))(function (resolve, reject) {
144
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
145
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
146
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
147
- step((generator = generator.apply(thisArg, _arguments || [])).next());
148
- });
149
- }
150
-
151
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
152
- var e = new Error(message);
153
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
154
- };
155
-
156
156
  class LocationCollector {
157
157
  constructor(config) {
158
158
  this.config = config;
@@ -13588,8 +13588,11 @@
13588
13588
  this.sendToBackend('/v1/analytics/identify', user);
13589
13589
  }
13590
13590
  startSession(session) {
13591
- // Send session start immediately to RUM endpoint
13592
- this.sendToBackend('/v1/rum/sessions', session);
13591
+ return __awaiter$1(this, void 0, void 0, function* () {
13592
+ // Send session start immediately to RUM endpoint
13593
+ // MUST await to ensure session is created before other requests
13594
+ yield this.sendToBackend('/v1/rum/sessions', session);
13595
+ });
13593
13596
  }
13594
13597
  sendError(error) {
13595
13598
  this.enqueue('error', error);
@@ -13874,7 +13877,6 @@
13874
13877
  * Initialize the DevSkin SDK
13875
13878
  */
13876
13879
  init(config) {
13877
- var _a;
13878
13880
  if (this.initialized) {
13879
13881
  console.warn('[DevSkin] SDK already initialized');
13880
13882
  return;
@@ -13897,69 +13899,71 @@
13897
13899
  this.locationCollector = new LocationCollector(this.config);
13898
13900
  this.browserCollector = new BrowserCollector(this.config);
13899
13901
  // Start session (will now include device/browser/location data)
13900
- this.startSession();
13901
- if (this.config.captureWebVitals) {
13902
- this.performanceCollector = new PerformanceCollector(this.config, this.transport);
13903
- this.performanceCollector.start();
13904
- }
13905
- if (this.config.captureErrors) {
13906
- this.errorCollector = new ErrorCollector(this.config, this.transport);
13907
- this.errorCollector.start();
13908
- }
13909
- if (this.config.captureNetworkRequests) {
13910
- this.networkCollector = new NetworkCollector(this.config, this.transport);
13911
- this.networkCollector.start();
13912
- }
13913
- // Initialize heatmap collector - SEMPRE habilitado
13914
- // Merge default heatmap config with user config
13915
- const heatmapConfig = Object.assign({ enabled: true, trackClicks: true, trackScroll: true, trackMouseMovement: true, mouseMoveSampling: 0.1 }, this.config.heatmapOptions);
13916
- this.config.heatmapOptions = heatmapConfig;
13917
- this.heatmapCollector = new HeatmapCollector(this.config, this.transport);
13918
- this.heatmapCollector.start();
13919
- // Initialize screenshot collector and capture page
13920
- this.screenshotCollector = new ScreenshotCollector(this.config, this.transport);
13921
- this.screenshotCollector.captureAndSend(this.sessionId, window.location.href);
13922
- if (this.config.debug) {
13923
- console.log('[DevSkin] Heatmap collection enabled (always on)');
13924
- }
13925
- // Initialize session recording with rrweb
13926
- if ((_a = this.config.sessionRecording) === null || _a === void 0 ? void 0 : _a.enabled) {
13927
- // Use RRWebRecorder for complete DOM recording
13928
- this.rrwebRecorder = new RRWebRecorder(this.sessionId, {
13929
- enabled: true,
13930
- sampleRate: this.config.sessionRecording.sampling || 0.5,
13931
- blockClass: 'rr-block',
13932
- ignoreClass: this.config.sessionRecording.ignoreClass || 'rr-ignore',
13933
- maskAllInputs: this.config.sessionRecording.maskAllInputs !== undefined
13934
- ? this.config.sessionRecording.maskAllInputs
13935
- : true,
13936
- maskInputOptions: {
13937
- password: true,
13938
- email: true,
13939
- tel: true,
13940
- },
13941
- recordCanvas: this.config.sessionRecording.recordCanvas || false,
13942
- collectFonts: true,
13943
- inlineStylesheet: true,
13944
- checkoutEveryNms: 5 * 60 * 1000, // Every 5 minutes
13945
- checkoutEveryNth: 200, // Every 200 events
13946
- }, (events) => {
13947
- var _a;
13948
- // Send rrweb events to backend
13949
- (_a = this.transport) === null || _a === void 0 ? void 0 : _a.sendRecordingEvents(this.sessionId, events);
13950
- });
13951
- // Wait 500ms before starting recording to ensure session is created in backend
13952
- // This prevents race condition where FullSnapshot is sent before session exists
13953
- setTimeout(() => {
13954
- var _a, _b;
13955
- (_a = this.rrwebRecorder) === null || _a === void 0 ? void 0 : _a.start();
13902
+ // Wait for session creation to complete before starting collectors
13903
+ this.startSession().then(() => {
13904
+ // Session created, now safe to start collectors that send data
13905
+ var _a, _b;
13906
+ if (this.config.captureWebVitals) {
13907
+ this.performanceCollector = new PerformanceCollector(this.config, this.transport);
13908
+ this.performanceCollector.start();
13909
+ }
13910
+ if (this.config.captureErrors) {
13911
+ this.errorCollector = new ErrorCollector(this.config, this.transport);
13912
+ this.errorCollector.start();
13913
+ }
13914
+ if (this.config.captureNetworkRequests) {
13915
+ this.networkCollector = new NetworkCollector(this.config, this.transport);
13916
+ this.networkCollector.start();
13917
+ }
13918
+ // Initialize heatmap collector - SEMPRE habilitado
13919
+ // Merge default heatmap config with user config
13920
+ const heatmapConfig = Object.assign({ enabled: true, trackClicks: true, trackScroll: true, trackMouseMovement: true, mouseMoveSampling: 0.1 }, this.config.heatmapOptions);
13921
+ this.config.heatmapOptions = heatmapConfig;
13922
+ this.heatmapCollector = new HeatmapCollector(this.config, this.transport);
13923
+ this.heatmapCollector.start();
13924
+ // Initialize screenshot collector and capture page
13925
+ this.screenshotCollector = new ScreenshotCollector(this.config, this.transport);
13926
+ this.screenshotCollector.captureAndSend(this.sessionId, window.location.href);
13927
+ if (this.config.debug) {
13928
+ console.log('[DevSkin] Heatmap collection enabled (always on)');
13929
+ }
13930
+ // Initialize session recording with rrweb
13931
+ if ((_a = this.config.sessionRecording) === null || _a === void 0 ? void 0 : _a.enabled) {
13932
+ // Use RRWebRecorder for complete DOM recording
13933
+ this.rrwebRecorder = new RRWebRecorder(this.sessionId, {
13934
+ enabled: true,
13935
+ sampleRate: this.config.sessionRecording.sampling || 0.5,
13936
+ blockClass: 'rr-block',
13937
+ ignoreClass: this.config.sessionRecording.ignoreClass || 'rr-ignore',
13938
+ maskAllInputs: this.config.sessionRecording.maskAllInputs !== undefined
13939
+ ? this.config.sessionRecording.maskAllInputs
13940
+ : true,
13941
+ maskInputOptions: {
13942
+ password: true,
13943
+ email: true,
13944
+ tel: true,
13945
+ },
13946
+ recordCanvas: this.config.sessionRecording.recordCanvas || false,
13947
+ collectFonts: true,
13948
+ inlineStylesheet: true,
13949
+ checkoutEveryNms: 5 * 60 * 1000, // Every 5 minutes
13950
+ checkoutEveryNth: 200, // Every 200 events
13951
+ }, (events) => {
13952
+ var _a;
13953
+ // Send rrweb events to backend
13954
+ (_a = this.transport) === null || _a === void 0 ? void 0 : _a.sendRecordingEvents(this.sessionId, events);
13955
+ });
13956
+ // Start recording immediately (session already created)
13957
+ this.rrwebRecorder.start();
13956
13958
  if ((_b = this.config) === null || _b === void 0 ? void 0 : _b.debug) {
13957
13959
  console.log('[DevSkin] RRWeb recording started for session:', this.sessionId);
13958
13960
  }
13959
- }, 500);
13960
- }
13961
- // Track initial page view
13962
- this.trackPageView();
13961
+ }
13962
+ // Track initial page view
13963
+ this.trackPageView();
13964
+ }).catch((err) => {
13965
+ console.error('[DevSkin] Failed to create session:', err);
13966
+ });
13963
13967
  // Track page visibility changes
13964
13968
  this.setupVisibilityTracking();
13965
13969
  // Track page unload
@@ -14084,36 +14088,39 @@
14084
14088
  * Private methods
14085
14089
  */
14086
14090
  startSession() {
14087
- var _a, _b, _c, _d, _e;
14088
- // Check if there's an active session (stored in sessionStorage to persist across page navigations)
14089
- const existingSessionId = sessionStorage.getItem('devskin_session_id');
14090
- const existingSessionStart = sessionStorage.getItem('devskin_session_start');
14091
- if (existingSessionId && existingSessionStart) {
14092
- // Resume existing session
14093
- this.sessionId = existingSessionId;
14094
- this.sessionStartTime = parseInt(existingSessionStart, 10);
14091
+ return __awaiter$1(this, void 0, void 0, function* () {
14092
+ var _a, _b, _c, _d, _e;
14093
+ // Check if there's an active session (stored in sessionStorage to persist across page navigations)
14094
+ const existingSessionId = sessionStorage.getItem('devskin_session_id');
14095
+ const existingSessionStart = sessionStorage.getItem('devskin_session_start');
14096
+ if (existingSessionId && existingSessionStart) {
14097
+ // Resume existing session
14098
+ this.sessionId = existingSessionId;
14099
+ this.sessionStartTime = parseInt(existingSessionStart, 10);
14100
+ // Set sessionId in transport so it can be added to network/performance requests
14101
+ (_a = this.transport) === null || _a === void 0 ? void 0 : _a.setSessionId(this.sessionId);
14102
+ if ((_b = this.config) === null || _b === void 0 ? void 0 : _b.debug) {
14103
+ console.log('[DevSkin] Resuming existing session:', this.sessionId);
14104
+ }
14105
+ // Send page view but DON'T create a new session
14106
+ // The session is already created, just continue it
14107
+ return;
14108
+ }
14109
+ // Create new session
14110
+ this.sessionId = this.generateId();
14111
+ this.sessionStartTime = Date.now();
14112
+ // Store in sessionStorage (persists across page navigations in same tab)
14113
+ sessionStorage.setItem('devskin_session_id', this.sessionId);
14114
+ sessionStorage.setItem('devskin_session_start', this.sessionStartTime.toString());
14095
14115
  // Set sessionId in transport so it can be added to network/performance requests
14096
- (_a = this.transport) === null || _a === void 0 ? void 0 : _a.setSessionId(this.sessionId);
14097
- if ((_b = this.config) === null || _b === void 0 ? void 0 : _b.debug) {
14098
- console.log('[DevSkin] Resuming existing session:', this.sessionId);
14116
+ (_c = this.transport) === null || _c === void 0 ? void 0 : _c.setSessionId(this.sessionId);
14117
+ const sessionData = Object.assign({ sessionId: this.sessionId, userId: this.userId || undefined, anonymousId: this.anonymousId, startedAt: new Date().toISOString(), platform: 'web' }, this.getContextData());
14118
+ // CRITICAL: Await session creation to ensure it exists before sending metrics/requests
14119
+ yield ((_d = this.transport) === null || _d === void 0 ? void 0 : _d.startSession(sessionData));
14120
+ if ((_e = this.config) === null || _e === void 0 ? void 0 : _e.debug) {
14121
+ console.log('[DevSkin] New session created:', this.sessionId);
14099
14122
  }
14100
- // Send page view but DON'T create a new session
14101
- // The session is already created, just continue it
14102
- return;
14103
- }
14104
- // Create new session
14105
- this.sessionId = this.generateId();
14106
- this.sessionStartTime = Date.now();
14107
- // Store in sessionStorage (persists across page navigations in same tab)
14108
- sessionStorage.setItem('devskin_session_id', this.sessionId);
14109
- sessionStorage.setItem('devskin_session_start', this.sessionStartTime.toString());
14110
- // Set sessionId in transport so it can be added to network/performance requests
14111
- (_c = this.transport) === null || _c === void 0 ? void 0 : _c.setSessionId(this.sessionId);
14112
- const sessionData = Object.assign({ sessionId: this.sessionId, userId: this.userId || undefined, anonymousId: this.anonymousId, startedAt: new Date().toISOString(), platform: 'web' }, this.getContextData());
14113
- (_d = this.transport) === null || _d === void 0 ? void 0 : _d.startSession(sessionData);
14114
- if ((_e = this.config) === null || _e === void 0 ? void 0 : _e.debug) {
14115
- console.log('[DevSkin] New session created:', this.sessionId);
14116
- }
14123
+ });
14117
14124
  }
14118
14125
  getContextData() {
14119
14126
  var _a, _b, _c, _d;