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