@affiliateo/web 4.9.1 → 4.9.2
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.
- package/README.md +2 -0
- package/dist/queue.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -270,6 +270,8 @@ the script tag, `data-chat-color`, `data-chat-icon-color`, `data-chat-send-color
|
|
|
270
270
|
|
|
271
271
|
## Changelog
|
|
272
272
|
|
|
273
|
+
- **4.9.2:** events are sent as plain text, so the browser no longer makes an
|
|
274
|
+
extra check request before each one. Nothing to change in your code.
|
|
273
275
|
- **4.9.1:** a different user signing in with `identify()` (no `logout()` in
|
|
274
276
|
between) now forgets the last person's Live Chat thread first, as a sign-out
|
|
275
277
|
does, and the bubble learns the new user without a reload. Signing in from
|
package/dist/queue.js
CHANGED
|
@@ -46,6 +46,10 @@ const MAX_RETRIES = 3;
|
|
|
46
46
|
const DEFAULT_MAX_QUEUE_SIZE = 100;
|
|
47
47
|
const DEFAULT_FLUSH_INTERVAL_MS = 5000;
|
|
48
48
|
const SIZE_FLUSH_THRESHOLD = 10;
|
|
49
|
+
// Plain text, not application/json: a JSON body makes the browser send an
|
|
50
|
+
// extra OPTIONS request before every event. The server reads the body as
|
|
51
|
+
// text and parses it itself, so nothing else changes.
|
|
52
|
+
const BODY_TYPE = 'text/plain;charset=UTF-8';
|
|
49
53
|
function lsGet(key) {
|
|
50
54
|
try {
|
|
51
55
|
return localStorage.getItem(key);
|
|
@@ -188,7 +192,7 @@ export class EventQueue {
|
|
|
188
192
|
try {
|
|
189
193
|
const res = await fetch(event.endpoint, {
|
|
190
194
|
method: 'POST',
|
|
191
|
-
headers: { 'Content-Type':
|
|
195
|
+
headers: { 'Content-Type': BODY_TYPE },
|
|
192
196
|
body: JSON.stringify(event.payload),
|
|
193
197
|
// keepalive lets the request survive a navigation. paired
|
|
194
198
|
// with the queue so even if this fetch errors, we'll retry.
|
|
@@ -243,7 +247,7 @@ export class EventQueue {
|
|
|
243
247
|
try {
|
|
244
248
|
fetch(event.endpoint, {
|
|
245
249
|
method: 'POST',
|
|
246
|
-
headers: { 'Content-Type':
|
|
250
|
+
headers: { 'Content-Type': BODY_TYPE },
|
|
247
251
|
body: JSON.stringify(event.payload),
|
|
248
252
|
keepalive: true,
|
|
249
253
|
}).catch(() => { });
|
|
@@ -256,7 +260,7 @@ export class EventQueue {
|
|
|
256
260
|
}
|
|
257
261
|
for (const event of this.queue) {
|
|
258
262
|
try {
|
|
259
|
-
navigator.sendBeacon(event.endpoint, new Blob([JSON.stringify(event.payload)], { type:
|
|
263
|
+
navigator.sendBeacon(event.endpoint, new Blob([JSON.stringify(event.payload)], { type: BODY_TYPE }));
|
|
260
264
|
}
|
|
261
265
|
catch { /* swallow */ }
|
|
262
266
|
}
|