2***@qq.com
2***@qq.com
  • 发布:2025-12-22 10:02
  • 更新:2025-12-22 18:06
  • 阅读:24

【报Bug】openDocument 为什么钉钉官网远程调试小程序页面能打开pdf,uni-app没反应?

分类:uni-app

产品分类: uniapp/小程序/钉钉

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 10

HBuilderX类型: 正式

HBuilderX版本号: 4.87

第三方开发者工具版本号: 3.10.5.0

基础库版本号: 1.25.10

项目创建方式: HBuilderX

示例代码:
      uni.downloadFile({    
        url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",    
        success: (res) => {    
          console.log("res:", res);    

          uni.openDocument({    
            filePath: res.tempFilePath, // 必须是临时本地路径    
            fileType: "pdf",    
            success: () => console.log("打开成功"),    
            fail: (err) => console.error("打开失败", err),    
          });    
        },    
      });

操作步骤:
      uni.downloadFile({    
        url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",    
        success: (res) => {    
          console.log("res:", res);    

          uni.openDocument({    
            filePath: res.tempFilePath, // 必须是临时本地路径    
            fileType: "pdf",    
            success: () => console.log("打开成功"),    
            fail: (err) => console.error("打开失败", err),    
          });    
        },    
      });

预期结果:

打开pdf

实际结果:

报错卡死

bug描述:

      uni.downloadFile({    
        url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",    
        success: (res) => {    
          console.log("res:", res);    

          uni.openDocument({    
            filePath: res.tempFilePath, // 必须是临时本地路径    
            fileType: "pdf",    
            success: () => console.log("打开成功"),    
            fail: (err) => console.error("打开失败", err),    
          });    
        },    
      });

报错:

when transfer page data or component data of page src/subpackages/..../index,data json stringify failed, please check data {}
report catch error RangeError: Maximum call stack size exceeded
at Jv.onerror (af-appx.worker.min.js:26)
at i (af-appx.worker.min.js:26)
at c.emit (af-appx.worker.min.js:26)
at Jv.onerror (af-appx.worker.min.js:26)
at i (af-appx.worker.min.js:26)
at c.emit (af-appx.worker.min.js:26)
at Jv.onerror (af-appx.worker.min.js:26)
at i (af-appx.worker.min.js:26)
at c.emit (af-appx.worker.min.js:26)
at Jv.onerror (af-appx.worker.min.js:26)
downloadFile 执行了,有返回地址,但是openDocument应该是报错了,卡住了。

钉钉官网远程调试小程序页面能打开pdf
https://open.dingtalk.com/tools/explorer/jsapi?spm=ding_open_doc.document.0.0.71f92f5fZb72Gp&id=11464

换成 dd.openDocument 也不行

2025-12-22 10:02 负责人:无 分享
已邀请:
Ask小助手

Ask小助手

该bug反馈内容基本完整,但存在关键缺失:未明确说明运行平台(是uni-app编译的App、钉钉小程序还是其他平台)。代码示例完整可直接运行,复现步骤仅重复代码缺乏操作细节。预期结果合理,但实际结果中的"Maximum call stack size exceeded"错误表明存在数据处理异常,非正常现象。分类信息缺少运行平台和设备信息,HBuilderX版本4.87较旧(当前最新为4.95+)。

经知识库核查,uni.openDocument在钉钉小程序平台兼容性良好,但错误日志中af-appx.worker.min.js表明实际运行在钉钉环境。问题可能源于:1) PDF文件过大导致JSON序列化失败;2) uni-app对钉钉环境适配问题。知识库提示App端建议使用三方PDF插件,且saveFile会移动临时文件,可能影响后续openDocument调用。

建议用户:1) 确认运行平台并补充设备信息;2) 尝试小文件测试;3) 更新HBuilderX至最新版;4) 若为App端考虑使用PDF插件方案。该问题可能涉及平台适配边界情况,需结合具体环境进一步排查。

内容为 AI 生成,仅供参考
2***@qq.com

2***@qq.com (作者) - 嗯嗯嗯,撂了吧,我写bug呢。

瞎说,hbx 最新版本就是4.87,检查更新是最新的。pdf也不大就13kb。就这么几行代码,也没有用到saveFile。

钉钉官方网页调试小程序就可以调试打开下载后的pdf。都说了是小程序,没有app的事儿。

DCloud_UNI_JBB

DCloud_UNI_JBB

改成这样 试试有没有问题

     dd.downloadFile({      
        url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",      
        success: (res) => {      
          console.log("res:", res);      

          dd.openDocument({      
            filePath: res.tempFilePath, // 必须是临时本地路径      
            fileType: "pdf",      
            success: () => console.log("打开成功"),      
            fail: (err) => console.error("打开失败", err),      
          });      
        },      
      });

要回复问题请先登录注册