@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 CHANGED
@@ -401,10 +401,7 @@ declare function logout(): Promise<void>;
401
401
 
402
402
  declare function hdH5Adapter(): void;
403
403
 
404
- declare const UniProxy: {
405
- chooseImage: any;
406
- pathToBase64: any;
407
- };
404
+ declare const UniProxy: any;
408
405
 
409
406
  declare class PageLifeCycle {
410
407
  state: string;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,3 @@
1
- import { pathToBase64 } from 'image-tools';
2
-
3
1
  /**
4
2
  * JSBridge 核心通信层
5
3
  *
@@ -225,9 +223,20 @@ class Bridge {
225
223
  const timeoutId = setTimeout(() => {
226
224
  reject(new Error(`${method} 调用超时`));
227
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
+ }
228
237
  // Android 调用
229
238
  if (this.platform === 'android' && this.bridge) {
230
- this.bridge.callHandler(method, data, (result) => {
239
+ this.bridge.callHandler(method, safeData, (result) => {
231
240
  clearTimeout(timeoutId);
232
241
  resolve(result);
233
242
  });
@@ -249,17 +258,6 @@ class Bridge {
249
258
  reject(err);
250
259
  }
251
260
  };
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
261
  handler.postMessage({
264
262
  handlerName: method,
265
263
  data: safeData,
@@ -1572,8 +1570,8 @@ class JsBridgeHandlers {
1572
1570
  //Cannot assign to read only property 'chooseImage' of object '[object Object]'
1573
1571
  // chooseImage是只读的,无法替换,只能用代理模式,如果有好方法替换可以删除这个类
1574
1572
  const UniProxy = {
1575
- chooseImage: uni.chooseImage,
1576
- pathToBase64: pathToBase64
1573
+ chooseImage: typeof uni !== 'undefined' ? uni.chooseImage : null,
1574
+ pathToBase64: null
1577
1575
  };
1578
1576
 
1579
1577
  function hdH5Adapter() {