rsclick-log-sdk-web 0.1.2 → 0.2.0
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 -3
- package/dist/index.global.js +3 -18
- package/dist/index.js +3 -18
- package/dist/sdk-transport.d.ts +1 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,9 +150,8 @@ SDK 默认上报以下字段:
|
|
|
150
150
|
|
|
151
151
|
传输策略:
|
|
152
152
|
|
|
153
|
-
1.
|
|
154
|
-
2.
|
|
155
|
-
3. 同源 `sendBeacon` 返回 `false` 或抛错时,回退到 `fetch(..., { keepalive: true })`
|
|
153
|
+
1. 统一使用 `fetch(..., { mode: "cors", credentials: "omit", keepalive: true })`
|
|
154
|
+
2. SDK 不再依赖 `navigator.sendBeacon`
|
|
156
155
|
|
|
157
156
|
## 发布说明
|
|
158
157
|
|
package/dist/index.global.js
CHANGED
|
@@ -231,35 +231,20 @@
|
|
|
231
231
|
// src/sdk-transport.ts
|
|
232
232
|
var dispatchCollect = async (browser, endpoint, payload) => {
|
|
233
233
|
const body = JSON.stringify(payload);
|
|
234
|
-
if (canUseBeacon(browser)) {
|
|
235
|
-
try {
|
|
236
|
-
const blob = createJsonBlob(browser, body);
|
|
237
|
-
const sent = browser.navigator?.sendBeacon?.(endpoint, blob);
|
|
238
|
-
if (sent) {
|
|
239
|
-
return { transport: "beacon" };
|
|
240
|
-
}
|
|
241
|
-
} catch {
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
234
|
const response = await postWithFetch(browser, endpoint, body);
|
|
245
235
|
return {
|
|
246
236
|
transport: "fetch",
|
|
247
237
|
response
|
|
248
238
|
};
|
|
249
239
|
};
|
|
250
|
-
var canUseBeacon = (browser) => typeof browser.navigator?.sendBeacon === "function";
|
|
251
|
-
var createJsonBlob = (browser, body) => {
|
|
252
|
-
if (browser.Blob) {
|
|
253
|
-
return new browser.Blob([body], { type: "application/json" });
|
|
254
|
-
}
|
|
255
|
-
return body;
|
|
256
|
-
};
|
|
257
240
|
var postWithFetch = async (browser, endpoint, body) => {
|
|
258
241
|
if (!browser.fetch) {
|
|
259
|
-
throw new Error("Tracking SDK requires fetch
|
|
242
|
+
throw new Error("Tracking SDK requires fetch support");
|
|
260
243
|
}
|
|
261
244
|
const response = await browser.fetch(endpoint, {
|
|
262
245
|
method: "POST",
|
|
246
|
+
mode: "cors",
|
|
247
|
+
credentials: "omit",
|
|
263
248
|
keepalive: true,
|
|
264
249
|
headers: {
|
|
265
250
|
"content-type": "application/json"
|
package/dist/index.js
CHANGED
|
@@ -196,35 +196,20 @@ var clearState = (storage) => {
|
|
|
196
196
|
// src/sdk-transport.ts
|
|
197
197
|
var dispatchCollect = async (browser, endpoint, payload) => {
|
|
198
198
|
const body = JSON.stringify(payload);
|
|
199
|
-
if (canUseBeacon(browser)) {
|
|
200
|
-
try {
|
|
201
|
-
const blob = createJsonBlob(browser, body);
|
|
202
|
-
const sent = browser.navigator?.sendBeacon?.(endpoint, blob);
|
|
203
|
-
if (sent) {
|
|
204
|
-
return { transport: "beacon" };
|
|
205
|
-
}
|
|
206
|
-
} catch {
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
199
|
const response = await postWithFetch(browser, endpoint, body);
|
|
210
200
|
return {
|
|
211
201
|
transport: "fetch",
|
|
212
202
|
response
|
|
213
203
|
};
|
|
214
204
|
};
|
|
215
|
-
var canUseBeacon = (browser) => typeof browser.navigator?.sendBeacon === "function";
|
|
216
|
-
var createJsonBlob = (browser, body) => {
|
|
217
|
-
if (browser.Blob) {
|
|
218
|
-
return new browser.Blob([body], { type: "application/json" });
|
|
219
|
-
}
|
|
220
|
-
return body;
|
|
221
|
-
};
|
|
222
205
|
var postWithFetch = async (browser, endpoint, body) => {
|
|
223
206
|
if (!browser.fetch) {
|
|
224
|
-
throw new Error("Tracking SDK requires fetch
|
|
207
|
+
throw new Error("Tracking SDK requires fetch support");
|
|
225
208
|
}
|
|
226
209
|
const response = await browser.fetch(endpoint, {
|
|
227
210
|
method: "POST",
|
|
211
|
+
mode: "cors",
|
|
212
|
+
credentials: "omit",
|
|
228
213
|
keepalive: true,
|
|
229
214
|
headers: {
|
|
230
215
|
"content-type": "application/json"
|
package/dist/sdk-transport.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TrackingCollectPayload, TrackingDispatchResult, TrackingResponse } from "./types";
|
|
2
2
|
import type { BrowserLike } from "./sdk-core";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 使用 fetch 发送采集请求。
|
|
5
5
|
*
|
|
6
6
|
* @param browser - 浏览器能力对象
|
|
7
7
|
* @param endpoint - 上报地址
|
|
@@ -9,21 +9,6 @@ import type { BrowserLike } from "./sdk-core";
|
|
|
9
9
|
* @returns 返回本次传输结果
|
|
10
10
|
*/
|
|
11
11
|
export declare const dispatchCollect: (browser: BrowserLike, endpoint: string, payload: TrackingCollectPayload) => Promise<TrackingDispatchResult>;
|
|
12
|
-
/**
|
|
13
|
-
* 判断当前环境是否支持 sendBeacon。
|
|
14
|
-
*
|
|
15
|
-
* @param browser - 浏览器能力对象
|
|
16
|
-
* @returns 返回是否可用
|
|
17
|
-
*/
|
|
18
|
-
export declare const canUseBeacon: (browser: BrowserLike) => boolean;
|
|
19
|
-
/**
|
|
20
|
-
* 创建 JSON Blob,缺失 Blob 构造器时直接返回字符串。
|
|
21
|
-
*
|
|
22
|
-
* @param browser - 浏览器能力对象
|
|
23
|
-
* @param body - JSON 字符串
|
|
24
|
-
* @returns 返回 Blob 或字符串
|
|
25
|
-
*/
|
|
26
|
-
export declare const createJsonBlob: (browser: BrowserLike, body: string) => Blob | string;
|
|
27
12
|
/**
|
|
28
13
|
* 使用 fetch 发送采集请求,并在响应为 JSON 时返回解析结果。
|
|
29
14
|
*
|