@tracelog/lib 0.0.4 → 0.0.6
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.
|
@@ -86,15 +86,25 @@ class SenderManager extends state_manager_1.StateManager {
|
|
|
86
86
|
try {
|
|
87
87
|
const response = await fetch(url, {
|
|
88
88
|
method: 'POST',
|
|
89
|
+
mode: 'cors',
|
|
90
|
+
credentials: 'omit',
|
|
91
|
+
body: payload,
|
|
89
92
|
headers: {
|
|
90
93
|
'Content-Type': 'application/json',
|
|
94
|
+
Origin: window.location.origin,
|
|
95
|
+
Referer: window.location.href,
|
|
91
96
|
},
|
|
92
|
-
body: payload,
|
|
93
97
|
});
|
|
94
98
|
return response.ok;
|
|
95
99
|
}
|
|
96
100
|
catch (error) {
|
|
97
|
-
|
|
101
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
102
|
+
const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('NotSameOrigin') || errorMessage.includes('blocked');
|
|
103
|
+
logging_1.debugLog.error('SenderManager', 'Failed to send events async', {
|
|
104
|
+
error: errorMessage,
|
|
105
|
+
isCorsError,
|
|
106
|
+
url: url.replace(/\/\/[^/]+/, '//[DOMAIN]'),
|
|
107
|
+
});
|
|
98
108
|
return false;
|
|
99
109
|
}
|
|
100
110
|
}
|
|
@@ -113,22 +123,33 @@ class SenderManager extends state_manager_1.StateManager {
|
|
|
113
123
|
return navigator.sendBeacon(url, payload);
|
|
114
124
|
}
|
|
115
125
|
sendSyncXHR(url, payload) {
|
|
126
|
+
const xhr = new XMLHttpRequest();
|
|
116
127
|
try {
|
|
117
|
-
const xhr = new XMLHttpRequest();
|
|
118
128
|
xhr.open('POST', url, false);
|
|
119
129
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
130
|
+
xhr.setRequestHeader('Origin', window.location.origin);
|
|
131
|
+
xhr.setRequestHeader('Referer', window.location.href);
|
|
132
|
+
xhr.withCredentials = false;
|
|
120
133
|
xhr.timeout = constants_1.SYNC_XHR_TIMEOUT_MS;
|
|
121
134
|
xhr.send(payload);
|
|
122
135
|
return xhr.status >= 200 && xhr.status < 300;
|
|
123
136
|
}
|
|
124
137
|
catch (error) {
|
|
125
|
-
|
|
138
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
139
|
+
const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('NotSameOrigin') || errorMessage.includes('blocked');
|
|
140
|
+
logging_1.debugLog.error('SenderManager', 'Sync XHR failed', {
|
|
141
|
+
error: errorMessage,
|
|
142
|
+
isCorsError,
|
|
143
|
+
status: xhr.status ?? 'unknown',
|
|
144
|
+
url: url.replace(/\/\/[^/]+/, '//[DOMAIN]'),
|
|
145
|
+
});
|
|
126
146
|
return false;
|
|
127
147
|
}
|
|
128
148
|
}
|
|
129
149
|
prepareRequest(body) {
|
|
130
150
|
const useLocalServer = this.get('config').id === types_1.SpecialProjectId.HttpLocal;
|
|
131
|
-
const
|
|
151
|
+
const baseUrl = useLocalServer ? window.location.origin : this.get('apiUrl');
|
|
152
|
+
const url = `${baseUrl}/collect`;
|
|
132
153
|
return {
|
|
133
154
|
url,
|
|
134
155
|
payload: JSON.stringify(body),
|
|
@@ -83,15 +83,25 @@ export class SenderManager extends StateManager {
|
|
|
83
83
|
try {
|
|
84
84
|
const response = await fetch(url, {
|
|
85
85
|
method: 'POST',
|
|
86
|
+
mode: 'cors',
|
|
87
|
+
credentials: 'omit',
|
|
88
|
+
body: payload,
|
|
86
89
|
headers: {
|
|
87
90
|
'Content-Type': 'application/json',
|
|
91
|
+
Origin: window.location.origin,
|
|
92
|
+
Referer: window.location.href,
|
|
88
93
|
},
|
|
89
|
-
body: payload,
|
|
90
94
|
});
|
|
91
95
|
return response.ok;
|
|
92
96
|
}
|
|
93
97
|
catch (error) {
|
|
94
|
-
|
|
98
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
99
|
+
const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('NotSameOrigin') || errorMessage.includes('blocked');
|
|
100
|
+
debugLog.error('SenderManager', 'Failed to send events async', {
|
|
101
|
+
error: errorMessage,
|
|
102
|
+
isCorsError,
|
|
103
|
+
url: url.replace(/\/\/[^/]+/, '//[DOMAIN]'),
|
|
104
|
+
});
|
|
95
105
|
return false;
|
|
96
106
|
}
|
|
97
107
|
}
|
|
@@ -110,22 +120,33 @@ export class SenderManager extends StateManager {
|
|
|
110
120
|
return navigator.sendBeacon(url, payload);
|
|
111
121
|
}
|
|
112
122
|
sendSyncXHR(url, payload) {
|
|
123
|
+
const xhr = new XMLHttpRequest();
|
|
113
124
|
try {
|
|
114
|
-
const xhr = new XMLHttpRequest();
|
|
115
125
|
xhr.open('POST', url, false);
|
|
116
126
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
127
|
+
xhr.setRequestHeader('Origin', window.location.origin);
|
|
128
|
+
xhr.setRequestHeader('Referer', window.location.href);
|
|
129
|
+
xhr.withCredentials = false;
|
|
117
130
|
xhr.timeout = SYNC_XHR_TIMEOUT_MS;
|
|
118
131
|
xhr.send(payload);
|
|
119
132
|
return xhr.status >= 200 && xhr.status < 300;
|
|
120
133
|
}
|
|
121
134
|
catch (error) {
|
|
122
|
-
|
|
135
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
136
|
+
const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('NotSameOrigin') || errorMessage.includes('blocked');
|
|
137
|
+
debugLog.error('SenderManager', 'Sync XHR failed', {
|
|
138
|
+
error: errorMessage,
|
|
139
|
+
isCorsError,
|
|
140
|
+
status: xhr.status ?? 'unknown',
|
|
141
|
+
url: url.replace(/\/\/[^/]+/, '//[DOMAIN]'),
|
|
142
|
+
});
|
|
123
143
|
return false;
|
|
124
144
|
}
|
|
125
145
|
}
|
|
126
146
|
prepareRequest(body) {
|
|
127
147
|
const useLocalServer = this.get('config').id === SpecialProjectId.HttpLocal;
|
|
128
|
-
const
|
|
148
|
+
const baseUrl = useLocalServer ? window.location.origin : this.get('apiUrl');
|
|
149
|
+
const url = `${baseUrl}/collect`;
|
|
129
150
|
return {
|
|
130
151
|
url,
|
|
131
152
|
payload: JSON.stringify(body),
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tracelog/lib",
|
|
3
3
|
"description": "JavaScript library for web analytics and real-time event tracking",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.6",
|
|
6
6
|
"main": "./dist/cjs/public-api.js",
|
|
7
7
|
"module": "./dist/esm/public-api.js",
|
|
8
8
|
"types": "./dist/esm/public-api.d.ts",
|