customer-chat-sdk 1.0.61 → 1.0.63
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 +9 -0
- package/dist/core/ScreenshotManager.d.ts.map +1 -1
- package/dist/customer-sdk.cjs.js +191 -20
- package/dist/customer-sdk.esm.js +191 -21
- package/dist/customer-sdk.min.js +2 -2
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -285,6 +285,10 @@ export declare class ScreenshotManager {
|
|
|
285
285
|
* 将 base64 data URL 转换为 ArrayBuffer
|
|
286
286
|
*/
|
|
287
287
|
private dataUrlToArrayBuffer;
|
|
288
|
+
/**
|
|
289
|
+
* 将 ArrayBuffer 转换为 base64 字符串
|
|
290
|
+
*/
|
|
291
|
+
private arrayBufferToBase64;
|
|
288
292
|
/**
|
|
289
293
|
* 构建二进制结构(按顺序:sign[14], type[1], topicLength[1], topic[topicLength], routingKey[8])
|
|
290
294
|
* 20 + 1 + 8 + 8 = 37 字节
|
|
@@ -321,6 +325,11 @@ export declare class ScreenshotManager {
|
|
|
321
325
|
* 启用/禁用截图功能
|
|
322
326
|
*/
|
|
323
327
|
enable(enabled: boolean): void;
|
|
328
|
+
/**
|
|
329
|
+
* 更新截图配置(动态更新,无需重新初始化)
|
|
330
|
+
* @param newOptions 要更新的配置项(部分更新)
|
|
331
|
+
*/
|
|
332
|
+
updateOptions(newOptions: Partial<ScreenshotOptions>): void;
|
|
324
333
|
/**
|
|
325
334
|
* 清理资源
|
|
326
335
|
*/
|
|
@@ -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,K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G,IAAI;IACvE,uBAAuB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAwD1E;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAO9B;;;OAGG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI;IA+D3D;;OAEG;IACH,OAAO,IAAI,IAAI;IAoEf;;OAEG;IACH,OAAO,CAAC,cAAc;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
|
@@ -14992,6 +14992,10 @@ class ScreenshotManager {
|
|
|
14992
14992
|
if (!this.options.silentMode) {
|
|
14993
14993
|
console.log('📸 使用 snapdom 引擎截图...');
|
|
14994
14994
|
}
|
|
14995
|
+
// 限制只截图可见区域(viewport),避免截图不可见区域
|
|
14996
|
+
// 注意:snapdom 可能不支持直接限制可见区域,所以这里只是添加警告
|
|
14997
|
+
let targetElement = element;
|
|
14998
|
+
let tempContainer = null;
|
|
14995
14999
|
try {
|
|
14996
15000
|
// 检查元素是否存在和可见
|
|
14997
15001
|
const rect = element.getBoundingClientRect();
|
|
@@ -15000,6 +15004,53 @@ class ScreenshotManager {
|
|
|
15000
15004
|
}
|
|
15001
15005
|
// 构建 snapdom 选项
|
|
15002
15006
|
const options = {};
|
|
15007
|
+
if (element === document.body || element === document.documentElement) {
|
|
15008
|
+
// 对于 body 或 html 元素,创建一个临时容器,只包含可见区域
|
|
15009
|
+
// 使用 html2canvas 的方式:创建一个固定大小的容器,只包含可见内容
|
|
15010
|
+
tempContainer = document.createElement('div');
|
|
15011
|
+
tempContainer.style.position = 'fixed';
|
|
15012
|
+
tempContainer.style.top = '0';
|
|
15013
|
+
tempContainer.style.left = '0';
|
|
15014
|
+
tempContainer.style.width = `${window.innerWidth}px`;
|
|
15015
|
+
tempContainer.style.height = `${window.innerHeight}px`;
|
|
15016
|
+
tempContainer.style.overflow = 'hidden';
|
|
15017
|
+
tempContainer.style.zIndex = '999999';
|
|
15018
|
+
tempContainer.style.pointerEvents = 'none';
|
|
15019
|
+
tempContainer.style.backgroundColor = window.getComputedStyle(document.body).backgroundColor || 'white';
|
|
15020
|
+
// 创建一个包装器,只包含可见区域的内容
|
|
15021
|
+
// 注意:这里不克隆整个 body,而是直接使用 body 作为父元素
|
|
15022
|
+
// 但限制容器的尺寸为可见区域
|
|
15023
|
+
document.body.appendChild(tempContainer);
|
|
15024
|
+
// 使用 body 作为目标,但通过容器限制范围
|
|
15025
|
+
// 实际上,我们需要直接截图 body,但限制尺寸
|
|
15026
|
+
// 由于 snapdom 可能不支持直接限制尺寸,我们使用一个更简单的方法:
|
|
15027
|
+
// 直接截图 body,但通过 CSS 限制其显示范围(但这会影响页面)
|
|
15028
|
+
// 更好的方法是:使用 html2canvas 的方式,创建一个 canvas 并只绘制可见区域
|
|
15029
|
+
// 简化方案:直接使用 body,但添加尺寸限制选项(如果 snapdom 支持)
|
|
15030
|
+
// 如果不支持,则只能截图整个 body
|
|
15031
|
+
targetElement = element;
|
|
15032
|
+
if (!this.options.silentMode) {
|
|
15033
|
+
console.log(`📸 注意:snapdom 将截图整个 body,建议使用 html2canvas 或 modern-screenshot 来限制可见区域`);
|
|
15034
|
+
console.log(`📸 可见区域尺寸: ${window.innerWidth}x${window.innerHeight}`);
|
|
15035
|
+
}
|
|
15036
|
+
// 清理临时容器(未使用)
|
|
15037
|
+
if (tempContainer && tempContainer.parentNode) {
|
|
15038
|
+
tempContainer.parentNode.removeChild(tempContainer);
|
|
15039
|
+
}
|
|
15040
|
+
tempContainer = null;
|
|
15041
|
+
}
|
|
15042
|
+
else {
|
|
15043
|
+
// 对于其他元素,检查是否完全可见
|
|
15044
|
+
const elementRect = element.getBoundingClientRect();
|
|
15045
|
+
const isFullyVisible = elementRect.top >= 0 &&
|
|
15046
|
+
elementRect.left >= 0 &&
|
|
15047
|
+
elementRect.bottom <= window.innerHeight &&
|
|
15048
|
+
elementRect.right <= window.innerWidth;
|
|
15049
|
+
if (!isFullyVisible && !this.options.silentMode) {
|
|
15050
|
+
console.warn(`📸 ⚠️ 元素部分不可见,snapdom 可能会截图整个元素(包括不可见部分)`);
|
|
15051
|
+
console.warn(`📸 建议:使用 html2canvas 或 modern-screenshot 来限制可见区域`);
|
|
15052
|
+
}
|
|
15053
|
+
}
|
|
15003
15054
|
// 如果配置了代理服务器,使用 useProxy 选项处理跨域图片和字体
|
|
15004
15055
|
// 参考: https://github.com/zumerlab/snapdom/blob/main/README_CN.md#跨域图片和字体-useproxy
|
|
15005
15056
|
// 只有当 useProxy 为 true 且 proxyUrl 存在时才使用代理
|
|
@@ -15034,16 +15085,16 @@ class ScreenshotManager {
|
|
|
15034
15085
|
switch (outputFormat) {
|
|
15035
15086
|
case 'jpeg':
|
|
15036
15087
|
// 使用 toJpg 快捷方法(snapdom 使用 jpg 作为方法名)
|
|
15037
|
-
img = await snapdom.toJpg(
|
|
15088
|
+
img = await snapdom.toJpg(targetElement, options);
|
|
15038
15089
|
break;
|
|
15039
15090
|
case 'webp':
|
|
15040
15091
|
// 使用 toWebp 快捷方法
|
|
15041
|
-
img = await snapdom.toWebp(
|
|
15092
|
+
img = await snapdom.toWebp(targetElement, options);
|
|
15042
15093
|
break;
|
|
15043
15094
|
case 'png':
|
|
15044
15095
|
default:
|
|
15045
15096
|
// 使用 toPng 快捷方法(默认)
|
|
15046
|
-
img = await snapdom.toPng(
|
|
15097
|
+
img = await snapdom.toPng(targetElement, options);
|
|
15047
15098
|
break;
|
|
15048
15099
|
}
|
|
15049
15100
|
// 获取 base64 数据(HTMLImageElement 的 src 属性包含 data URL)
|
|
@@ -15052,12 +15103,28 @@ class ScreenshotManager {
|
|
|
15052
15103
|
if (!dataUrl || dataUrl.length < 100) {
|
|
15053
15104
|
throw new Error('生成的 base64 数据无效或过短');
|
|
15054
15105
|
}
|
|
15106
|
+
// 清理临时容器(如果存在)
|
|
15107
|
+
if (tempContainer !== null) {
|
|
15108
|
+
const container = tempContainer;
|
|
15109
|
+
const parent = container.parentNode;
|
|
15110
|
+
if (parent) {
|
|
15111
|
+
parent.removeChild(container);
|
|
15112
|
+
}
|
|
15113
|
+
}
|
|
15055
15114
|
if (!this.options.silentMode) {
|
|
15056
15115
|
console.log(`📸 snapdom 截图成功!格式: ${outputFormat}, 尺寸: ${img.width}x${img.height}`);
|
|
15057
15116
|
}
|
|
15058
15117
|
return dataUrl;
|
|
15059
15118
|
}
|
|
15060
15119
|
catch (error) {
|
|
15120
|
+
// 确保清理临时容器(即使出错)
|
|
15121
|
+
if (tempContainer !== null) {
|
|
15122
|
+
const container = tempContainer;
|
|
15123
|
+
const parent = container.parentNode;
|
|
15124
|
+
if (parent) {
|
|
15125
|
+
parent.removeChild(container);
|
|
15126
|
+
}
|
|
15127
|
+
}
|
|
15061
15128
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
15062
15129
|
const errorName = error instanceof Error ? error.name : 'Unknown';
|
|
15063
15130
|
// 针对不同类型的错误给出具体提示
|
|
@@ -15454,19 +15521,21 @@ class ScreenshotManager {
|
|
|
15454
15521
|
console.log('📸 使用 modern-screenshot 引擎截图(Worker 模式)...');
|
|
15455
15522
|
}
|
|
15456
15523
|
try {
|
|
15457
|
-
//
|
|
15458
|
-
// 对于 document.body
|
|
15524
|
+
// 获取元素的实际尺寸
|
|
15525
|
+
// 对于 document.body,使用窗口可见区域尺寸(而不是完整滚动内容),避免截图过大
|
|
15459
15526
|
let elementWidth;
|
|
15460
15527
|
let elementHeight;
|
|
15461
15528
|
if (element === document.body || element === document.documentElement) {
|
|
15462
|
-
// 对于 body 或 html
|
|
15463
|
-
|
|
15464
|
-
|
|
15529
|
+
// 对于 body 或 html 元素,使用窗口可见区域尺寸(viewport)
|
|
15530
|
+
// 这样可以避免截图整个页面(包括不可见区域),减少图片大小
|
|
15531
|
+
elementWidth = window.innerWidth;
|
|
15532
|
+
elementHeight = window.innerHeight;
|
|
15465
15533
|
}
|
|
15466
15534
|
else {
|
|
15467
|
-
//
|
|
15468
|
-
|
|
15469
|
-
|
|
15535
|
+
// 对于其他元素,使用元素的可见尺寸(clientWidth/clientHeight)
|
|
15536
|
+
// 如果元素有滚动,只截图可见部分
|
|
15537
|
+
elementWidth = element.clientWidth || element.offsetWidth || element.scrollWidth;
|
|
15538
|
+
elementHeight = element.clientHeight || element.offsetHeight || element.scrollHeight;
|
|
15470
15539
|
}
|
|
15471
15540
|
if (!this.options.silentMode) {
|
|
15472
15541
|
console.log(`📸 目标元素: ${element.tagName}${element.id ? '#' + element.id : ''}${element.className ? '.' + element.className.split(' ').join('.') : ''}`);
|
|
@@ -15490,10 +15559,10 @@ class ScreenshotManager {
|
|
|
15490
15559
|
// 计算压缩后的尺寸(对所有元素都应用,包括 document.body)
|
|
15491
15560
|
// 这样可以避免生成过大的截图,减少 base64 大小
|
|
15492
15561
|
const { width, height } = this.calculateCompressedSize(elementWidth, elementHeight, this.options.maxWidth, this.options.maxHeight);
|
|
15493
|
-
//
|
|
15494
|
-
//
|
|
15495
|
-
const finalWidth = width
|
|
15496
|
-
const finalHeight = height
|
|
15562
|
+
// 使用计算后的压缩尺寸(确保不超过 maxWidth/maxHeight)
|
|
15563
|
+
// 对于 body 元素,已经使用了 window.innerWidth/innerHeight,所以直接使用压缩尺寸即可
|
|
15564
|
+
const finalWidth = width;
|
|
15565
|
+
const finalHeight = height;
|
|
15497
15566
|
// 处理跨域图片的函数
|
|
15498
15567
|
const handleCrossOriginImage = async (url) => {
|
|
15499
15568
|
// 如果是 data URL 或 blob URL,直接返回
|
|
@@ -17118,6 +17187,18 @@ class ScreenshotManager {
|
|
|
17118
17187
|
}
|
|
17119
17188
|
return u8arr.buffer;
|
|
17120
17189
|
}
|
|
17190
|
+
/**
|
|
17191
|
+
* 将 ArrayBuffer 转换为 base64 字符串
|
|
17192
|
+
*/
|
|
17193
|
+
arrayBufferToBase64(buffer) {
|
|
17194
|
+
const bytes = new Uint8Array(buffer);
|
|
17195
|
+
// 使用循环构建字符串,避免 String.fromCharCode.apply 的参数数量限制
|
|
17196
|
+
let binaryStr = '';
|
|
17197
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
17198
|
+
binaryStr += String.fromCharCode(bytes[i]);
|
|
17199
|
+
}
|
|
17200
|
+
return btoa(binaryStr);
|
|
17201
|
+
}
|
|
17121
17202
|
/**
|
|
17122
17203
|
* 构建二进制结构(按顺序:sign[14], type[1], topicLength[1], topic[topicLength], routingKey[8])
|
|
17123
17204
|
* 20 + 1 + 8 + 8 = 37 字节
|
|
@@ -17146,11 +17227,8 @@ class ScreenshotManager {
|
|
|
17146
17227
|
const topicArray = new Uint8Array(buffer, offset, topicLength);
|
|
17147
17228
|
topicArray.set(topicBytes);
|
|
17148
17229
|
offset += topicLength;
|
|
17149
|
-
//
|
|
17150
|
-
|
|
17151
|
-
offset += 1;
|
|
17152
|
-
// routingKey: 8字节
|
|
17153
|
-
const routingKeyBytes = encoder.encode(config.routingKey);
|
|
17230
|
+
// routingKey:
|
|
17231
|
+
const routingKeyBytes = encoder.encode(config.routingKey.trim());
|
|
17154
17232
|
const routingKeyLength = routingKeyBytes.length;
|
|
17155
17233
|
// routingKeyLength: 1字节
|
|
17156
17234
|
view.setUint8(offset, routingKeyLength);
|
|
@@ -17205,6 +17283,16 @@ class ScreenshotManager {
|
|
|
17205
17283
|
// 将截图转换为 ArrayBuffer
|
|
17206
17284
|
const imageBuffer = this.dataUrlToArrayBuffer(latestScreenshot);
|
|
17207
17285
|
const imageBufferSize = imageBuffer.byteLength;
|
|
17286
|
+
// 将 imageBuffer 转换为 base64 字符串(用于和接收端对比)
|
|
17287
|
+
const imageBufferBase64 = this.arrayBufferToBase64(imageBuffer);
|
|
17288
|
+
// 打印 imageBuffer 的 base64 编码(用于和接收端对比)
|
|
17289
|
+
if (!this.options.silentMode) {
|
|
17290
|
+
console.log('📸 [发送前] imageBuffer 转换为 Base64(用于和接收端对比):');
|
|
17291
|
+
console.log(` Base64 长度: ${imageBufferBase64.length} 字符`);
|
|
17292
|
+
console.log(` Base64 完整字符串:`);
|
|
17293
|
+
console.log(imageBufferBase64);
|
|
17294
|
+
console.log(` Data URL: data:image/webp;base64,${imageBufferBase64}`);
|
|
17295
|
+
}
|
|
17208
17296
|
// 构建配置的二进制结构
|
|
17209
17297
|
const configBuffer = this.buildBinaryConfig(config);
|
|
17210
17298
|
const configBufferSize = configBuffer.byteLength;
|
|
@@ -17372,6 +17460,71 @@ class ScreenshotManager {
|
|
|
17372
17460
|
this.stopScreenshot();
|
|
17373
17461
|
}
|
|
17374
17462
|
}
|
|
17463
|
+
/**
|
|
17464
|
+
* 更新截图配置(动态更新,无需重新初始化)
|
|
17465
|
+
* @param newOptions 要更新的配置项(部分更新)
|
|
17466
|
+
*/
|
|
17467
|
+
updateOptions(newOptions) {
|
|
17468
|
+
const oldEngine = this.options.engine;
|
|
17469
|
+
const newEngine = newOptions.engine;
|
|
17470
|
+
// 更新配置
|
|
17471
|
+
if (newOptions.engine !== undefined) {
|
|
17472
|
+
this.options.engine = newOptions.engine;
|
|
17473
|
+
}
|
|
17474
|
+
if (newOptions.quality !== undefined) {
|
|
17475
|
+
this.options.quality = newOptions.quality;
|
|
17476
|
+
}
|
|
17477
|
+
if (newOptions.scale !== undefined) {
|
|
17478
|
+
this.options.scale = newOptions.scale;
|
|
17479
|
+
}
|
|
17480
|
+
if (newOptions.maxWidth !== undefined) {
|
|
17481
|
+
this.options.maxWidth = newOptions.maxWidth;
|
|
17482
|
+
}
|
|
17483
|
+
if (newOptions.maxHeight !== undefined) {
|
|
17484
|
+
this.options.maxHeight = newOptions.maxHeight;
|
|
17485
|
+
}
|
|
17486
|
+
if (newOptions.outputFormat !== undefined) {
|
|
17487
|
+
this.options.outputFormat = newOptions.outputFormat;
|
|
17488
|
+
}
|
|
17489
|
+
if (newOptions.compress !== undefined) {
|
|
17490
|
+
this.options.compress = newOptions.compress;
|
|
17491
|
+
}
|
|
17492
|
+
if (newOptions.silentMode !== undefined) {
|
|
17493
|
+
this.options.silentMode = newOptions.silentMode;
|
|
17494
|
+
}
|
|
17495
|
+
if (newOptions.proxyUrl !== undefined) {
|
|
17496
|
+
this.options.proxyUrl = newOptions.proxyUrl;
|
|
17497
|
+
}
|
|
17498
|
+
if (newOptions.useProxy !== undefined) {
|
|
17499
|
+
this.options.useProxy = newOptions.useProxy;
|
|
17500
|
+
}
|
|
17501
|
+
// 如果引擎改变了,需要清理 context(下次截图时会使用新引擎)
|
|
17502
|
+
if (newEngine && newEngine !== oldEngine) {
|
|
17503
|
+
if (this.screenshotContext) {
|
|
17504
|
+
try {
|
|
17505
|
+
destroyContext(this.screenshotContext);
|
|
17506
|
+
if (!this.options.silentMode) {
|
|
17507
|
+
console.log(`📸 引擎已从 ${oldEngine} 切换到 ${newEngine},已清理旧 context`);
|
|
17508
|
+
}
|
|
17509
|
+
}
|
|
17510
|
+
catch (e) {
|
|
17511
|
+
// 忽略清理错误
|
|
17512
|
+
}
|
|
17513
|
+
this.screenshotContext = null;
|
|
17514
|
+
this.contextElement = null;
|
|
17515
|
+
this.contextOptionsHash = '';
|
|
17516
|
+
this.contextContentHash = '';
|
|
17517
|
+
this.contextLastUpdateTime = 0;
|
|
17518
|
+
}
|
|
17519
|
+
if (!this.options.silentMode) {
|
|
17520
|
+
console.log(`📸 截图引擎已更新: ${oldEngine} → ${newEngine}`);
|
|
17521
|
+
console.log(`📸 下次截图时将使用新引擎: ${newEngine}`);
|
|
17522
|
+
}
|
|
17523
|
+
}
|
|
17524
|
+
else if (!this.options.silentMode) {
|
|
17525
|
+
console.log('📸 截图配置已更新');
|
|
17526
|
+
}
|
|
17527
|
+
}
|
|
17375
17528
|
/**
|
|
17376
17529
|
* 清理资源
|
|
17377
17530
|
*/
|
|
@@ -21012,6 +21165,18 @@ class CustomerServiceSDK {
|
|
|
21012
21165
|
getScreenshotState() {
|
|
21013
21166
|
return this.screenshotManager?.getState() || null;
|
|
21014
21167
|
}
|
|
21168
|
+
/**
|
|
21169
|
+
* 更新截图配置(动态更新,无需重新初始化)
|
|
21170
|
+
* @param options 要更新的配置项(部分更新)
|
|
21171
|
+
*/
|
|
21172
|
+
updateScreenshotOptions(options) {
|
|
21173
|
+
if (!this.screenshotManager) {
|
|
21174
|
+
console.warn('截图管理器未初始化,无法更新配置');
|
|
21175
|
+
return;
|
|
21176
|
+
}
|
|
21177
|
+
this.screenshotManager.updateOptions(options);
|
|
21178
|
+
console.log('📸 截图配置已更新:', options);
|
|
21179
|
+
}
|
|
21015
21180
|
/**
|
|
21016
21181
|
* 销毁 SDK
|
|
21017
21182
|
*/
|
|
@@ -21177,6 +21342,10 @@ const getScreenshotState = () => {
|
|
|
21177
21342
|
const sdk = getInstance();
|
|
21178
21343
|
return sdk.getScreenshotState();
|
|
21179
21344
|
};
|
|
21345
|
+
const updateScreenshotOptions = (options) => {
|
|
21346
|
+
const sdk = getInstance();
|
|
21347
|
+
sdk.updateScreenshotOptions(options);
|
|
21348
|
+
};
|
|
21180
21349
|
// 默认导出
|
|
21181
21350
|
var index = {
|
|
21182
21351
|
init,
|
|
@@ -21197,6 +21366,7 @@ var index = {
|
|
|
21197
21366
|
captureScreenshot,
|
|
21198
21367
|
enableScreenshot,
|
|
21199
21368
|
getScreenshotState,
|
|
21369
|
+
updateScreenshotOptions,
|
|
21200
21370
|
destroy
|
|
21201
21371
|
};
|
|
21202
21372
|
|
|
@@ -21221,3 +21391,4 @@ exports.setIconStyle = setIconStyle;
|
|
|
21221
21391
|
exports.setScreenshotTarget = setScreenshotTarget;
|
|
21222
21392
|
exports.showIcon = showIcon;
|
|
21223
21393
|
exports.showNotification = showNotification;
|
|
21394
|
+
exports.updateScreenshotOptions = updateScreenshotOptions;
|