@hd-front-end/jsbridge-sdk 1.0.3 → 1.0.5
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/index.d.ts +1 -4
- package/dist/index.esm.js +14 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +14 -16
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +18 -18
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var imageTools = require('image-tools');
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* JSBridge 核心通信层
|
|
7
5
|
*
|
|
@@ -227,9 +225,20 @@ class Bridge {
|
|
|
227
225
|
const timeoutId = setTimeout(() => {
|
|
228
226
|
reject(new Error(`${method} 调用超时`));
|
|
229
227
|
}, 10000);
|
|
228
|
+
// 核心防御:防止 DataCloneError 和 Vue Proxy 序列化失败
|
|
229
|
+
// 剥离可能存在的不可序列化对象(如 success/fail 回调函数,或者 Vue 的 Proxy 对象)
|
|
230
|
+
let safeData = data;
|
|
231
|
+
if (data && typeof data === 'object') {
|
|
232
|
+
try {
|
|
233
|
+
safeData = JSON.parse(JSON.stringify(data));
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
// 忽略异常,保留原数据
|
|
237
|
+
}
|
|
238
|
+
}
|
|
230
239
|
// Android 调用
|
|
231
240
|
if (this.platform === 'android' && this.bridge) {
|
|
232
|
-
this.bridge.callHandler(method,
|
|
241
|
+
this.bridge.callHandler(method, safeData, (result) => {
|
|
233
242
|
clearTimeout(timeoutId);
|
|
234
243
|
resolve(result);
|
|
235
244
|
});
|
|
@@ -251,17 +260,6 @@ class Bridge {
|
|
|
251
260
|
reject(err);
|
|
252
261
|
}
|
|
253
262
|
};
|
|
254
|
-
// 核心防御:防止 DataCloneError
|
|
255
|
-
// 剥离可能存在的不可序列化对象(如 success/fail 回调函数)
|
|
256
|
-
let safeData = data;
|
|
257
|
-
if (data && typeof data === 'object') {
|
|
258
|
-
try {
|
|
259
|
-
safeData = JSON.parse(JSON.stringify(data));
|
|
260
|
-
}
|
|
261
|
-
catch (e) {
|
|
262
|
-
// 忽略异常,保留原数据
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
263
|
handler.postMessage({
|
|
266
264
|
handlerName: method,
|
|
267
265
|
data: safeData,
|
|
@@ -1574,8 +1572,8 @@ class JsBridgeHandlers {
|
|
|
1574
1572
|
//Cannot assign to read only property 'chooseImage' of object '[object Object]'
|
|
1575
1573
|
// chooseImage是只读的,无法替换,只能用代理模式,如果有好方法替换可以删除这个类
|
|
1576
1574
|
const UniProxy = {
|
|
1577
|
-
chooseImage: uni.chooseImage,
|
|
1578
|
-
pathToBase64:
|
|
1575
|
+
chooseImage: typeof uni !== 'undefined' ? uni.chooseImage : null,
|
|
1576
|
+
pathToBase64: null
|
|
1579
1577
|
};
|
|
1580
1578
|
|
|
1581
1579
|
function hdH5Adapter() {
|