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