customer-chat-sdk 1.0.42 → 1.0.44
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/dist/core/ScreenshotManager.d.ts +3 -26
- package/dist/core/ScreenshotManager.d.ts.map +1 -1
- package/dist/customer-sdk.cjs.js +42 -235
- package/dist/customer-sdk.esm.js +42 -235
- package/dist/customer-sdk.min.js +2 -2
- package/dist/index.d.ts +3 -18
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -53,6 +53,7 @@ export interface BinaryConfig {
|
|
|
53
53
|
topic: string;
|
|
54
54
|
routingKey: string;
|
|
55
55
|
ttl: number;
|
|
56
|
+
duration: number;
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
* 截图管理器
|
|
@@ -67,10 +68,7 @@ export declare class ScreenshotManager {
|
|
|
67
68
|
private lastScreenshotTime;
|
|
68
69
|
private error;
|
|
69
70
|
private isEnabled;
|
|
70
|
-
private isUploading;
|
|
71
71
|
private uploadError;
|
|
72
|
-
private uploadProgress;
|
|
73
|
-
private currentUploadConfig;
|
|
74
72
|
private currentBinaryConfig;
|
|
75
73
|
private sendToIframeCallback;
|
|
76
74
|
private worker;
|
|
@@ -121,17 +119,9 @@ export declare class ScreenshotManager {
|
|
|
121
119
|
*/
|
|
122
120
|
private handleIframeMessage;
|
|
123
121
|
/**
|
|
124
|
-
*
|
|
125
|
-
*/
|
|
126
|
-
private takeScreenshotAndUpload;
|
|
127
|
-
/**
|
|
128
|
-
* 解析二进制配置(新格式)
|
|
122
|
+
* 解析二进制配置
|
|
129
123
|
*/
|
|
130
124
|
private parseBinaryConfig;
|
|
131
|
-
/**
|
|
132
|
-
* 解析上传配置
|
|
133
|
-
*/
|
|
134
|
-
private parseUploadConfig;
|
|
135
125
|
/**
|
|
136
126
|
* 开始轮询截图
|
|
137
127
|
*/
|
|
@@ -291,14 +281,6 @@ export declare class ScreenshotManager {
|
|
|
291
281
|
* 移除全局错误处理器
|
|
292
282
|
*/
|
|
293
283
|
private removeGlobalErrorHandlers;
|
|
294
|
-
/**
|
|
295
|
-
* 上传截图到 S3
|
|
296
|
-
*/
|
|
297
|
-
private uploadScreenshot;
|
|
298
|
-
/**
|
|
299
|
-
* 将 base64 data URL 转换为 Blob
|
|
300
|
-
*/
|
|
301
|
-
private dataUrlToBlob;
|
|
302
284
|
/**
|
|
303
285
|
* 将 base64 data URL 转换为 ArrayBuffer
|
|
304
286
|
*/
|
|
@@ -358,13 +340,8 @@ export declare class ScreenshotManager {
|
|
|
358
340
|
lastScreenshotTime: number;
|
|
359
341
|
error: string | null;
|
|
360
342
|
isEnabled: boolean;
|
|
361
|
-
isUploading: boolean;
|
|
362
343
|
uploadError: string | null;
|
|
363
|
-
|
|
364
|
-
success: number;
|
|
365
|
-
failed: number;
|
|
366
|
-
};
|
|
367
|
-
currentUploadConfig: UploadConfig | null;
|
|
344
|
+
currentBinaryConfig: BinaryConfig | null;
|
|
368
345
|
};
|
|
369
346
|
}
|
|
370
347
|
//# sourceMappingURL=ScreenshotManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScreenshotManager.d.ts","sourceRoot":"","sources":["../../src/core/ScreenshotManager.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAA;IACtC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAA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AAc;IAkBtB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAqCtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAoBzB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;OAEG;IACH,QAAQ;;;;;;;;;CAWT"}
|
package/dist/customer-sdk.cjs.js
CHANGED
|
@@ -14314,11 +14314,8 @@ class ScreenshotManager {
|
|
|
14314
14314
|
this.error = null;
|
|
14315
14315
|
this.isEnabled = false;
|
|
14316
14316
|
// 上传相关状态
|
|
14317
|
-
this.isUploading = false;
|
|
14318
14317
|
this.uploadError = null;
|
|
14319
|
-
this.
|
|
14320
|
-
this.currentUploadConfig = null;
|
|
14321
|
-
this.currentBinaryConfig = null; // 二进制配置(新格式)
|
|
14318
|
+
this.currentBinaryConfig = null; // 二进制配置
|
|
14322
14319
|
this.sendToIframeCallback = null; // 发送消息到 iframe 的回调函数
|
|
14323
14320
|
// WebWorker 相关
|
|
14324
14321
|
this.worker = null;
|
|
@@ -14374,7 +14371,7 @@ class ScreenshotManager {
|
|
|
14374
14371
|
useProxy: options.useProxy ?? true, // 默认启用代理(如果配置了proxyUrl)
|
|
14375
14372
|
engine: options.engine ?? 'modern-screenshot',
|
|
14376
14373
|
corsMode: options.corsMode ?? 'canvas-proxy',
|
|
14377
|
-
silentMode: options.silentMode
|
|
14374
|
+
silentMode: options.silentMode !== undefined ? options.silentMode : false, // 默认 false,显示日志
|
|
14378
14375
|
maxRetries: options.maxRetries ?? 2,
|
|
14379
14376
|
preloadImages: options.preloadImages ?? false, // 默认不预加载,按需加载
|
|
14380
14377
|
maxConcurrentDownloads: options.maxConcurrentDownloads ?? 10, // 增加并发数
|
|
@@ -14552,9 +14549,8 @@ class ScreenshotManager {
|
|
|
14552
14549
|
// 尝试解析为二进制配置(新格式)
|
|
14553
14550
|
const binaryConfig = this.parseBinaryConfig(event.data.data);
|
|
14554
14551
|
if (binaryConfig) {
|
|
14555
|
-
//
|
|
14552
|
+
// 二进制配置
|
|
14556
14553
|
this.currentBinaryConfig = binaryConfig;
|
|
14557
|
-
this.currentUploadConfig = null; // 清除旧格式配置
|
|
14558
14554
|
// 根据 ttl 判断是否开启截图功能
|
|
14559
14555
|
const currentTime = Date.now();
|
|
14560
14556
|
const isValid = binaryConfig.ttl > 0 && binaryConfig.ttl > currentTime;
|
|
@@ -14566,8 +14562,8 @@ class ScreenshotManager {
|
|
|
14566
14562
|
}
|
|
14567
14563
|
this.isEnabled = true;
|
|
14568
14564
|
}
|
|
14569
|
-
//
|
|
14570
|
-
this.dynamicInterval = this.options.interval;
|
|
14565
|
+
// 设置动态轮询间隔(使用配置中的 duration)
|
|
14566
|
+
this.dynamicInterval = binaryConfig.duration || this.options.interval;
|
|
14571
14567
|
// 计算剩余有效时间(毫秒)
|
|
14572
14568
|
const remainingTime = binaryConfig.ttl - currentTime;
|
|
14573
14569
|
// 启动或更新截图轮询
|
|
@@ -14612,73 +14608,9 @@ class ScreenshotManager {
|
|
|
14612
14608
|
}
|
|
14613
14609
|
return;
|
|
14614
14610
|
}
|
|
14615
|
-
//
|
|
14616
|
-
|
|
14617
|
-
|
|
14618
|
-
console.error('📸 [iframe] 解析配置失败');
|
|
14619
|
-
this.uploadError = '解析上传配置失败';
|
|
14620
|
-
return;
|
|
14621
|
-
}
|
|
14622
|
-
// 保存当前配置
|
|
14623
|
-
this.currentUploadConfig = config;
|
|
14624
|
-
this.currentBinaryConfig = null; // 清除二进制配置
|
|
14625
|
-
// 根据 ttl 判断是否开启截图功能
|
|
14626
|
-
// ttl == 0 表示禁用,ttl > 0 且大于当前时间表示有效
|
|
14627
|
-
const currentTime = Date.now();
|
|
14628
|
-
const isValid = config.ttl > 0 && config.ttl > currentTime;
|
|
14629
|
-
if (isValid) {
|
|
14630
|
-
// 启用截图功能
|
|
14631
|
-
if (!this.isEnabled) {
|
|
14632
|
-
if (!this.options.silentMode) {
|
|
14633
|
-
console.log('📸 [iframe] 启用截图功能');
|
|
14634
|
-
}
|
|
14635
|
-
this.isEnabled = true;
|
|
14636
|
-
}
|
|
14637
|
-
// 设置动态轮询间隔(使用 duration,单位:毫秒)
|
|
14638
|
-
this.dynamicInterval = config.duration || this.options.interval;
|
|
14639
|
-
// 计算剩余有效时间(毫秒)
|
|
14640
|
-
const remainingTime = config.ttl - currentTime;
|
|
14641
|
-
// 启动或更新截图轮询
|
|
14642
|
-
if (!this.options.silentMode) {
|
|
14643
|
-
const remainingMinutes = Math.ceil(remainingTime / 60000);
|
|
14644
|
-
console.log(`📸 [iframe] 设置轮询间隔: ${this.dynamicInterval}ms,剩余有效时间: ${remainingMinutes}分钟`);
|
|
14645
|
-
}
|
|
14646
|
-
// 先执行一次截图,等待完成后再上传
|
|
14647
|
-
this.takeScreenshotAndUpload(config);
|
|
14648
|
-
// 设置过期定时器
|
|
14649
|
-
if (this.expirationTimer) {
|
|
14650
|
-
clearTimeout(this.expirationTimer);
|
|
14651
|
-
this.expirationTimer = null;
|
|
14652
|
-
}
|
|
14653
|
-
this.expirationTimer = setTimeout(() => {
|
|
14654
|
-
if (!this.options.silentMode) {
|
|
14655
|
-
console.log('📸 [iframe] 上传配置已过期,停止截图');
|
|
14656
|
-
}
|
|
14657
|
-
this.stopScreenshot();
|
|
14658
|
-
this.isEnabled = false;
|
|
14659
|
-
this.currentUploadConfig = null;
|
|
14660
|
-
this.expirationTimer = null;
|
|
14661
|
-
}, remainingTime);
|
|
14662
|
-
}
|
|
14663
|
-
else {
|
|
14664
|
-
// 禁用截图功能(ttl == 0 或已过期)
|
|
14665
|
-
if (!this.options.silentMode) {
|
|
14666
|
-
if (config.ttl === 0) {
|
|
14667
|
-
console.log('📸 [iframe] ttl == 0,禁用截图功能');
|
|
14668
|
-
}
|
|
14669
|
-
else {
|
|
14670
|
-
console.log('📸 [iframe] ttl 已过期,禁用截图功能');
|
|
14671
|
-
}
|
|
14672
|
-
}
|
|
14673
|
-
this.stopScreenshot();
|
|
14674
|
-
this.isEnabled = false;
|
|
14675
|
-
this.currentUploadConfig = null;
|
|
14676
|
-
if (this.expirationTimer) {
|
|
14677
|
-
clearTimeout(this.expirationTimer);
|
|
14678
|
-
this.expirationTimer = null;
|
|
14679
|
-
}
|
|
14680
|
-
return;
|
|
14681
|
-
}
|
|
14611
|
+
// 如果不是二进制配置格式,记录错误
|
|
14612
|
+
console.error('📸 [iframe] 解析配置失败:未识别的配置格式');
|
|
14613
|
+
this.uploadError = '解析配置失败:仅支持二进制配置格式';
|
|
14682
14614
|
}
|
|
14683
14615
|
catch (error) {
|
|
14684
14616
|
console.error('📸 [iframe] 处理消息失败:', error);
|
|
@@ -14686,63 +14618,7 @@ class ScreenshotManager {
|
|
|
14686
14618
|
}
|
|
14687
14619
|
}
|
|
14688
14620
|
/**
|
|
14689
|
-
*
|
|
14690
|
-
*/
|
|
14691
|
-
async takeScreenshotAndUpload(config) {
|
|
14692
|
-
// 如果已经在运行,先停止再重新开始(更新间隔)
|
|
14693
|
-
if (this.isRunning) {
|
|
14694
|
-
if (!this.options.silentMode) {
|
|
14695
|
-
console.log(`📸 更新轮询间隔: ${this.dynamicInterval || this.options.interval}ms`);
|
|
14696
|
-
}
|
|
14697
|
-
this.stopScreenshot();
|
|
14698
|
-
}
|
|
14699
|
-
// 启动轮询
|
|
14700
|
-
this.startScreenshot(this.dynamicInterval || config.duration || this.options.interval);
|
|
14701
|
-
// 等待第一次截图完成
|
|
14702
|
-
try {
|
|
14703
|
-
const success = await this.takeScreenshot();
|
|
14704
|
-
if (success) {
|
|
14705
|
-
// 截图完成后,等待一小段时间确保数据已保存
|
|
14706
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
14707
|
-
// 获取最新截图并上传
|
|
14708
|
-
const latestScreenshot = this.getLatestScreenshot();
|
|
14709
|
-
if (latestScreenshot) {
|
|
14710
|
-
// 执行上传
|
|
14711
|
-
this.isUploading = true;
|
|
14712
|
-
this.uploadError = null;
|
|
14713
|
-
this.uploadScreenshot(latestScreenshot, config)
|
|
14714
|
-
.then((success) => {
|
|
14715
|
-
if (success) {
|
|
14716
|
-
if (!this.options.silentMode) {
|
|
14717
|
-
console.log('📸 [iframe] ✅ 截图上传成功');
|
|
14718
|
-
}
|
|
14719
|
-
}
|
|
14720
|
-
else {
|
|
14721
|
-
console.error('📸 [iframe] ❌ 截图上传失败');
|
|
14722
|
-
}
|
|
14723
|
-
})
|
|
14724
|
-
.catch((error) => {
|
|
14725
|
-
console.error('📸 [iframe] ❌ 上传异常:', error);
|
|
14726
|
-
this.uploadError = error instanceof Error ? error.message : String(error);
|
|
14727
|
-
})
|
|
14728
|
-
.finally(() => {
|
|
14729
|
-
this.isUploading = false;
|
|
14730
|
-
});
|
|
14731
|
-
}
|
|
14732
|
-
else {
|
|
14733
|
-
if (!this.options.silentMode) {
|
|
14734
|
-
console.warn('📸 [iframe] 截图完成但未找到截图数据');
|
|
14735
|
-
}
|
|
14736
|
-
}
|
|
14737
|
-
}
|
|
14738
|
-
}
|
|
14739
|
-
catch (error) {
|
|
14740
|
-
console.error('📸 [iframe] 截图失败:', error);
|
|
14741
|
-
this.uploadError = error instanceof Error ? error.message : String(error);
|
|
14742
|
-
}
|
|
14743
|
-
}
|
|
14744
|
-
/**
|
|
14745
|
-
* 解析二进制配置(新格式)
|
|
14621
|
+
* 解析二进制配置
|
|
14746
14622
|
*/
|
|
14747
14623
|
parseBinaryConfig(data) {
|
|
14748
14624
|
try {
|
|
@@ -14759,7 +14635,10 @@ class ScreenshotManager {
|
|
|
14759
14635
|
type: config.type,
|
|
14760
14636
|
topic: config.topic,
|
|
14761
14637
|
routingKey: config.routingKey,
|
|
14762
|
-
ttl: config.ttl
|
|
14638
|
+
ttl: config.ttl,
|
|
14639
|
+
duration: typeof config.duration === 'number' && config.duration > 0
|
|
14640
|
+
? config.duration
|
|
14641
|
+
: this.options.interval // 如果没有提供或无效,使用默认间隔
|
|
14763
14642
|
};
|
|
14764
14643
|
}
|
|
14765
14644
|
return null;
|
|
@@ -14769,38 +14648,6 @@ class ScreenshotManager {
|
|
|
14769
14648
|
return null;
|
|
14770
14649
|
}
|
|
14771
14650
|
}
|
|
14772
|
-
/**
|
|
14773
|
-
* 解析上传配置
|
|
14774
|
-
*/
|
|
14775
|
-
parseUploadConfig(data) {
|
|
14776
|
-
try {
|
|
14777
|
-
const configStr = typeof data === 'string' ? data : JSON.stringify(data);
|
|
14778
|
-
const config = JSON.parse(configStr);
|
|
14779
|
-
if (!config.uploadUrl || !config.contentType) {
|
|
14780
|
-
console.error('📸 [上传] 配置缺少必需字段:', config);
|
|
14781
|
-
return null;
|
|
14782
|
-
}
|
|
14783
|
-
// 确保 duration 存在,如果没有则使用默认值
|
|
14784
|
-
if (typeof config.duration !== 'number' || config.duration <= 0) {
|
|
14785
|
-
config.duration = this.options.interval;
|
|
14786
|
-
}
|
|
14787
|
-
// 确保 ttl 存在,如果没有则尝试从 expirationMinutes 转换(兼容旧格式)
|
|
14788
|
-
if (typeof config.ttl !== 'number') {
|
|
14789
|
-
if (typeof config.expirationMinutes === 'number' && config.expirationMinutes > 0) {
|
|
14790
|
-
// 兼容旧格式:将 expirationMinutes 转换为 ttl
|
|
14791
|
-
config.ttl = Date.now() + config.expirationMinutes * 60 * 1000;
|
|
14792
|
-
}
|
|
14793
|
-
else {
|
|
14794
|
-
config.ttl = 0; // 默认禁用
|
|
14795
|
-
}
|
|
14796
|
-
}
|
|
14797
|
-
return config;
|
|
14798
|
-
}
|
|
14799
|
-
catch (error) {
|
|
14800
|
-
console.error('📸 [上传] 解析配置失败:', error, '原始数据:', data);
|
|
14801
|
-
return null;
|
|
14802
|
-
}
|
|
14803
|
-
}
|
|
14804
14651
|
/**
|
|
14805
14652
|
* 开始轮询截图
|
|
14806
14653
|
*/
|
|
@@ -14830,27 +14677,31 @@ class ScreenshotManager {
|
|
|
14830
14677
|
if (this.isRunning && this.isEnabled && !document.hidden) {
|
|
14831
14678
|
try {
|
|
14832
14679
|
await this.takeScreenshot();
|
|
14833
|
-
// 如果配置了上传,且当前有上传配置,自动上传
|
|
14834
|
-
if (this.currentUploadConfig) {
|
|
14835
|
-
const latestScreenshot = this.getLatestScreenshot();
|
|
14836
|
-
if (latestScreenshot && !this.isUploading) {
|
|
14837
|
-
this.uploadScreenshot(latestScreenshot, this.currentUploadConfig)
|
|
14838
|
-
.catch((error) => {
|
|
14839
|
-
console.error('📸 [轮询] 自动上传失败:', error);
|
|
14840
|
-
});
|
|
14841
|
-
}
|
|
14842
|
-
}
|
|
14843
14680
|
// 如果配置了二进制模式,发送二进制数据
|
|
14844
14681
|
if (this.currentBinaryConfig) {
|
|
14845
14682
|
const latestScreenshot = this.getLatestScreenshot();
|
|
14846
14683
|
if (latestScreenshot) {
|
|
14847
14684
|
try {
|
|
14685
|
+
// 计算 base64 大小
|
|
14686
|
+
const base64Data = latestScreenshot.split(',')[1] || '';
|
|
14687
|
+
const base64Size = base64Data.length;
|
|
14848
14688
|
// 将截图转换为 ArrayBuffer
|
|
14849
14689
|
const imageBuffer = this.dataUrlToArrayBuffer(latestScreenshot);
|
|
14690
|
+
const imageBufferSize = imageBuffer.byteLength;
|
|
14850
14691
|
// 构建配置的二进制结构
|
|
14851
14692
|
const configBuffer = this.buildBinaryConfig(this.currentBinaryConfig);
|
|
14693
|
+
const configBufferSize = configBuffer.byteLength;
|
|
14852
14694
|
// 合并配置字节和图片字节(配置在前)
|
|
14853
14695
|
const combinedBuffer = this.combineBinaryData(configBuffer, imageBuffer);
|
|
14696
|
+
const combinedBufferSize = combinedBuffer.byteLength;
|
|
14697
|
+
// 打印大小信息
|
|
14698
|
+
if (!this.options.silentMode) {
|
|
14699
|
+
console.log('📸 [轮询-大小统计]');
|
|
14700
|
+
console.log(` Base64 大小: ${base64Size} 字符`);
|
|
14701
|
+
console.log(` 图片字节大小: ${(imageBufferSize / 1024).toFixed(2)} KB (${imageBufferSize} 字节)`);
|
|
14702
|
+
console.log(` 配置字节大小: ${configBufferSize} 字节`);
|
|
14703
|
+
console.log(` 拼接后总大小: ${(combinedBufferSize / 1024).toFixed(2)} KB (${combinedBufferSize} 字节)`);
|
|
14704
|
+
}
|
|
14854
14705
|
// 发送二进制数据到 iframe
|
|
14855
14706
|
if (this.sendToIframeCallback) {
|
|
14856
14707
|
const message = {
|
|
@@ -16922,62 +16773,6 @@ class ScreenshotManager {
|
|
|
16922
16773
|
this.globalRejectionHandler = null;
|
|
16923
16774
|
}
|
|
16924
16775
|
}
|
|
16925
|
-
/**
|
|
16926
|
-
* 上传截图到 S3
|
|
16927
|
-
*/
|
|
16928
|
-
async uploadScreenshot(dataUrl, config) {
|
|
16929
|
-
try {
|
|
16930
|
-
if (!this.options.silentMode) {
|
|
16931
|
-
console.log('📸 [上传] 开始上传截图...');
|
|
16932
|
-
}
|
|
16933
|
-
const blob = this.dataUrlToBlob(dataUrl, config.contentType);
|
|
16934
|
-
// 使用标准的 fetch 方法(与 demo 代码一致)
|
|
16935
|
-
const response = await fetch(config.uploadUrl, {
|
|
16936
|
-
method: 'PUT',
|
|
16937
|
-
body: blob,
|
|
16938
|
-
headers: {
|
|
16939
|
-
'Content-Type': config.contentType
|
|
16940
|
-
}
|
|
16941
|
-
});
|
|
16942
|
-
if (response.status === 200 || response.status === 204) {
|
|
16943
|
-
if (!this.options.silentMode) {
|
|
16944
|
-
console.log('📸 [上传] ✅ 上传成功');
|
|
16945
|
-
}
|
|
16946
|
-
this.uploadProgress.success++;
|
|
16947
|
-
return true;
|
|
16948
|
-
}
|
|
16949
|
-
else {
|
|
16950
|
-
const errorText = await response.text().catch(() => '');
|
|
16951
|
-
const errorMsg = `上传失败: HTTP ${response.status} ${response.statusText}${errorText ? ` - ${errorText.substring(0, 200)}` : ''}`;
|
|
16952
|
-
console.error('📸 [上传] ❌', errorMsg);
|
|
16953
|
-
this.uploadError = errorMsg;
|
|
16954
|
-
this.uploadProgress.failed++;
|
|
16955
|
-
return false;
|
|
16956
|
-
}
|
|
16957
|
-
}
|
|
16958
|
-
catch (error) {
|
|
16959
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
16960
|
-
console.error('📸 [上传] ❌ 上传异常:', errorMsg);
|
|
16961
|
-
this.uploadError = `上传异常: ${errorMsg}`;
|
|
16962
|
-
this.uploadProgress.failed++;
|
|
16963
|
-
return false;
|
|
16964
|
-
}
|
|
16965
|
-
}
|
|
16966
|
-
/**
|
|
16967
|
-
* 将 base64 data URL 转换为 Blob
|
|
16968
|
-
*/
|
|
16969
|
-
dataUrlToBlob(dataUrl, contentType) {
|
|
16970
|
-
const arr = dataUrl.split(',');
|
|
16971
|
-
const mimeMatch = arr[0].match(/:(.*?);/);
|
|
16972
|
-
const mime = mimeMatch ? mimeMatch[1] : contentType;
|
|
16973
|
-
const bstr = atob(arr[1]);
|
|
16974
|
-
let n = bstr.length;
|
|
16975
|
-
const u8arr = new Uint8Array(n);
|
|
16976
|
-
while (n--) {
|
|
16977
|
-
u8arr[n] = bstr.charCodeAt(n);
|
|
16978
|
-
}
|
|
16979
|
-
return new Blob([u8arr], { type: mime });
|
|
16980
|
-
}
|
|
16981
16776
|
/**
|
|
16982
16777
|
* 将 base64 data URL 转换为 ArrayBuffer
|
|
16983
16778
|
*/
|
|
@@ -17057,12 +16852,26 @@ class ScreenshotManager {
|
|
|
17057
16852
|
const latestScreenshot = this.getLatestScreenshot();
|
|
17058
16853
|
if (latestScreenshot) {
|
|
17059
16854
|
try {
|
|
16855
|
+
// 计算 base64 大小
|
|
16856
|
+
const base64Data = latestScreenshot.split(',')[1] || '';
|
|
16857
|
+
const base64Size = base64Data.length;
|
|
17060
16858
|
// 将截图转换为 ArrayBuffer
|
|
17061
16859
|
const imageBuffer = this.dataUrlToArrayBuffer(latestScreenshot);
|
|
16860
|
+
const imageBufferSize = imageBuffer.byteLength;
|
|
17062
16861
|
// 构建配置的二进制结构
|
|
17063
16862
|
const configBuffer = this.buildBinaryConfig(config);
|
|
16863
|
+
const configBufferSize = configBuffer.byteLength;
|
|
17064
16864
|
// 合并配置字节和图片字节(配置在前)
|
|
17065
16865
|
const combinedBuffer = this.combineBinaryData(configBuffer, imageBuffer);
|
|
16866
|
+
const combinedBufferSize = combinedBuffer.byteLength;
|
|
16867
|
+
// 打印大小信息
|
|
16868
|
+
if (!this.options.silentMode) {
|
|
16869
|
+
console.log('📸 [大小统计]');
|
|
16870
|
+
console.log(` Base64 大小: ${base64Size} 字符`);
|
|
16871
|
+
console.log(` 图片字节大小: ${(imageBufferSize / 1024).toFixed(2)} KB (${imageBufferSize} 字节)`);
|
|
16872
|
+
console.log(` 配置字节大小: ${configBufferSize} 字节`);
|
|
16873
|
+
console.log(` 拼接后总大小: ${(combinedBufferSize / 1024).toFixed(2)} KB (${combinedBufferSize} 字节)`);
|
|
16874
|
+
}
|
|
17066
16875
|
// 发送二进制数据到 iframe
|
|
17067
16876
|
if (this.sendToIframeCallback) {
|
|
17068
16877
|
const message = {
|
|
@@ -17277,10 +17086,8 @@ class ScreenshotManager {
|
|
|
17277
17086
|
lastScreenshotTime: this.lastScreenshotTime,
|
|
17278
17087
|
error: this.error,
|
|
17279
17088
|
isEnabled: this.isEnabled,
|
|
17280
|
-
isUploading: this.isUploading,
|
|
17281
17089
|
uploadError: this.uploadError,
|
|
17282
|
-
|
|
17283
|
-
currentUploadConfig: this.currentUploadConfig
|
|
17090
|
+
currentBinaryConfig: this.currentBinaryConfig
|
|
17284
17091
|
};
|
|
17285
17092
|
}
|
|
17286
17093
|
}
|