惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
量子位
腾讯CDC
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
B
Blog
S
SegmentFault 最新的问题
P
Privacy & Cybersecurity Law Blog
T
Threatpost
博客园 - 聂微东
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
C
Check Point Blog
N
Netflix TechBlog - Medium
D
DataBreaches.Net
爱范儿
爱范儿
IT之家
IT之家
S
Secure Thoughts
M
MIT News - Artificial intelligence
NISL@THU
NISL@THU
C
Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
有赞技术团队
有赞技术团队
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
Schneier on Security
Schneier on Security
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
雷峰网
雷峰网
Project Zero
Project Zero
博客园 - Franky
H
Heimdal Security Blog
A
About on SuperTechFans
Security Latest
Security Latest
Webroot Blog
Webroot Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - herryLo

LangChainJs之基础模型(一) 什么是生成式AI 白嫖党体验Claude Code 关于Web GIS基础知识 直播流IOS无法播放问题排查 如何全方位提升博客站点? Windows 10 专业版下推送docker镜像到harbor报错:x509: certificate relies on legacy Common Name field, use SANs instead A Philosophy of Software Design 软件设计哲学 浅读-《深入浅出Nodejs》 腾讯云对象存储 COS搭建个人网站 你知道,前端工程部署有哪些方式嘛? 2022前端开发知识总结归纳(前端掌握知识) 如何使用Docker构建前端项目 Rancher前端服务发布 知识扩展-SQL查询基础 Axios源码解析:请求响应拦截器 AntV G2可视化引擎, 有用过嘛? 弄懂!ES6中的Iterator迭代器 🔥[译] 正交设计组件的好处 GitHub Action一键部署配置,值得拥有 小程序开发指南之性能优化
web前端pdf.js预览pdf实例创建报错:Array. prototype` contains unexpected enumerable properties
herryLo · 2023-04-24 · via 博客园 - herryLo

作者:Herrylo

使用pdf.min.js是预览pdf文件,但是在实例化时异常报错,下面是实例化的代码

var loadingTask = window.pdfjsLib.getDocument(url);
console.log(loadingTask);
this.pageNum = 1;
this.pageRendering = false;
this.pageNumPending = null;
loadingTask.promise.then((pdfDoc_) => {
   this.pdfDoc = pdfDoc_;
   document.getElementById('custom_pdf_viewer_pagecount').textContent =
      '共' + this.pdfDoc.numPages + '页';
   this.renderPage(this.pageNum);
});

以上代码其实没有任何问题,但是报了下面的错误:

details: Error: The `Array.prototype` contains unexpected enumerable properties: max, min, mean, rep, pip; thus breaking e.g. `for...in` iteration of `Array`s.
​
message: The `Array.prototype` contains unexpected enumerable properties: max, min, mean, rep, pip; thus breaking e.g. `for...in` iteration of `Array`s.
name: "UnknownErrorException"

pdf.js在其他项目使用过,但在新项目中使用,却报了这个问题,我在网上寻找解决方案,发现有人遇到过类似的问题 github pdf.js 异常报错

在pdf.js的 github issue上,我找到了问题原因,就像报错信息提示的一样,存在js库对 Array.prototype 进行了扩展,pdf.js认为这是在错误地扩展对象和/或数组,并且以一种破坏例如for…的方式进行交互。

解决方法

在控制台上打印 Array.prototype,看看 Array.prototype是不是被扩展,出现了下面的这些方法:max, min, mean, rep, pip,或是其他的方法,其他方法也是一样。

pdf.js认为以上的这些方法:这是在错误地扩展对象和/或数组,并且以一种破坏例如for…的方式进行交互。

将Array.prototype扩展方法移除,只需要找进行Array.prototype扩展的第三方库,并且在代码中移除它就可以,这样,问题就被解决了。