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