@hd-front-end/jsbridge-sdk 1.0.4 → 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.js CHANGED
@@ -225,9 +225,20 @@ class Bridge {
225
225
  const timeoutId = setTimeout(() => {
226
226
  reject(new Error(`${method} 调用超时`));
227
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
+ }
228
239
  // Android 调用
229
240
  if (this.platform === 'android' && this.bridge) {
230
- this.bridge.callHandler(method, data, (result) => {
241
+ this.bridge.callHandler(method, safeData, (result) => {
231
242
  clearTimeout(timeoutId);
232
243
  resolve(result);
233
244
  });
@@ -249,17 +260,6 @@ class Bridge {
249
260
  reject(err);
250
261
  }
251
262
  };
252
- // 核心防御:防止 DataCloneError
253
- // 剥离可能存在的不可序列化对象(如 success/fail 回调函数)
254
- let safeData = data;
255
- if (data && typeof data === 'object') {
256
- try {
257
- safeData = JSON.parse(JSON.stringify(data));
258
- }
259
- catch (e) {
260
- // 忽略异常,保留原数据
261
- }
262
- }
263
263
  handler.postMessage({
264
264
  handlerName: method,
265
265
  data: safeData,