@devskin/browser-sdk 1.0.14 → 1.0.15

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.
@@ -5777,11 +5777,21 @@
5777
5777
  let lastError = null;
5778
5778
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
5779
5779
  try {
5780
- yield this.sendToBackend('/v1/rum/recordings', {
5781
- session_id: sessionId,
5782
- events,
5783
- timestamp: new Date().toISOString(),
5784
- });
5780
+ // Use XMLHttpRequest for large payloads (more reliable than fetch for large data)
5781
+ if (payloadSize > 100000) { // > 100KB
5782
+ yield this.sendToBackendXHR('/v1/rum/recordings', {
5783
+ session_id: sessionId,
5784
+ events,
5785
+ timestamp: new Date().toISOString(),
5786
+ });
5787
+ }
5788
+ else {
5789
+ yield this.sendToBackend('/v1/rum/recordings', {
5790
+ session_id: sessionId,
5791
+ events,
5792
+ timestamp: new Date().toISOString(),
5793
+ });
5794
+ }
5785
5795
  console.log(`[DevSkin SDK] ✅ Recording events sent successfully${attempt > 1 ? ` (attempt ${attempt})` : ''}`);
5786
5796
  return; // Success, exit
5787
5797
  }
@@ -5856,6 +5866,57 @@
5856
5866
  return '/v1/analytics/events';
5857
5867
  }
5858
5868
  }
5869
+ sendToBackendXHR(endpoint, data) {
5870
+ return __awaiter$1(this, void 0, void 0, function* () {
5871
+ const url = `${this.apiUrl}${endpoint}`;
5872
+ const payload = Object.assign(Object.assign({}, data), { apiKey: this.config.apiKey, appId: this.config.appId, environment: this.config.environment, release: this.config.release });
5873
+ // Apply beforeSend hook if provided
5874
+ if (this.config.beforeSend) {
5875
+ const processed = this.config.beforeSend(payload);
5876
+ if (!processed) {
5877
+ // Hook returned null, don't send
5878
+ return;
5879
+ }
5880
+ }
5881
+ return new Promise((resolve, reject) => {
5882
+ const xhr = new XMLHttpRequest();
5883
+ xhr.open('POST', url, true);
5884
+ xhr.setRequestHeader('Content-Type', 'application/json');
5885
+ xhr.setRequestHeader('Authorization', `Bearer ${this.config.apiKey}`);
5886
+ xhr.onload = () => {
5887
+ if (xhr.status >= 200 && xhr.status < 300) {
5888
+ if (this.config.debug) {
5889
+ console.log('[DevSkin] Data sent successfully via XHR:', endpoint);
5890
+ }
5891
+ resolve();
5892
+ }
5893
+ else {
5894
+ console.error('[DevSkin] XHR HTTP Error:', xhr.status, xhr.responseText);
5895
+ reject(new Error(`HTTP ${xhr.status}: ${xhr.statusText}`));
5896
+ }
5897
+ };
5898
+ xhr.onerror = () => {
5899
+ console.error('[DevSkin] XHR network error:', endpoint);
5900
+ reject(new Error('Network error'));
5901
+ };
5902
+ xhr.ontimeout = () => {
5903
+ console.error('[DevSkin] XHR timeout:', endpoint);
5904
+ reject(new Error('Request timeout'));
5905
+ };
5906
+ // Set a generous timeout for large payloads (30 seconds)
5907
+ xhr.timeout = 30000;
5908
+ try {
5909
+ const body = JSON.stringify(payload);
5910
+ console.log(`[DevSkin SDK] Using XMLHttpRequest for large payload (${(body.length / 1024).toFixed(2)} KB)`);
5911
+ xhr.send(body);
5912
+ }
5913
+ catch (error) {
5914
+ console.error('[DevSkin] Failed to send XHR request:', error);
5915
+ reject(error);
5916
+ }
5917
+ });
5918
+ });
5919
+ }
5859
5920
  sendToBackend(endpoint_1, data_1) {
5860
5921
  return __awaiter$1(this, arguments, void 0, function* (endpoint, data, useBeacon = false) {
5861
5922
  const url = `${this.apiUrl}${endpoint}`;