首页 > 其他分享 >web前端pdf.js预览pdf实例创建报错:Array. prototype` contains unexpected enumerable properties

web前端pdf.js预览pdf实例创建报错:Array. prototype` contains unexpected enumerable properties

时间:2023-04-24 14:36:52浏览次数:47  
标签:web contains js 报错 pdf Array prototype

使用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: $family, $constructor, each, clone, clean, invoke, associate, link, contains, append, getLast, getRandom, include, combine, erase, empty, flatten, pick, hexToRgb, rgbToHex; thus breaking e.g. `for...in` iteration of `Array`s."
​
message: "The `Array.prototype` contains unexpected enumerable properties: $family, $constructor, each, clone, clean, invoke, associate, link, contains, append, getLast, getRandom, include, combine, erase, empty, flatten, pick, hexToRgb, rgbToHex; 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是不是被扩展,出现了下面的这些方法:

$family, $constructor, each, clone, clean, invoke, associate, link, contains, append, getLast, getRandom

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

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


标签:web,contains,js,报错,pdf,Array,prototype
From: https://www.cnblogs.com/liuheng/p/17349398.html

相关文章

  • uiautomatorviewer.bat 多种报错问题的解决办法
    问题一:使用Android_sdk--tools里的uiautomatorviewer.bat定位页面元素时报错:Remoteobjectdoesn'texists解决办法:使用uiautomatorviewer.bat时要关闭Appium。因为它们都使用同一个端口来连接模拟器。 问题二:使用uiautomatorviewer.bat定位页面元素时报错:Unexpected......
  • springboot集成redis时总报错Connection refused: no further information: localhost
    nacos上配置的关于redis的key值不是springboot需要的固定写法如:sping.redis.host=spring.redis.port=sping.redis.password=spring.redis.database=我写的是一个自定义的key如com.dream.redis.host改为springboot认识的即可其他和springboot集成的组件类似,切记......
  • web3 产品介绍 MyEtherWallet 方便和智能合约交互的钱包
    MyEtherWallet(简称MEW)是一款流行的去中心化以太坊钱包,它允许用户在安全且简单的界面中管理自己的以太坊资产。在本文中,我们将介绍MyEtherWallet的主要特点、功能以及如何使用它来管理以太坊资产。一、MyEtherWallet的特点安全性:MyEtherWallet是一款去中心化的钱包,用户可以保存......
  • vue移动端使用(pdfh5) 组件预览PDF
    1、安装插件npmipdfh52、在页面内引入组件importPdfh5from"pdfh5";import"pdfh5/css/pdfh5.css";3、写一个展示pdf文件的容器  <divid="pdfType"></div>4、封装在事件中 initPdf(){      this.pdfh5=''      this.pdfh......
  • eWebEditor 实现ctrl+v粘贴图片并上传、word粘贴带图片
    ​如何做到ueditor批量上传word图片?1、前端引用代码<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>......
  • 如何解决安卓七,客户端用的webview打包视频切换有暂停图标
    可以用video中的html5poster属性poster="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7为最小的base64图片并且透明也可以选择黑色:data:image/gif;b......
  • npm i 报错 unable to resolve dependency tree
    错误:问题原因:安装包各个版本冲突解决办法:npmi--legacy-peer-deps忽略各种报错命令npmi--legacy-peer-deps--ignore-scripts--registry=https://registry.npm.taobao.org然后重新安装 npminstall 或者 cnpmi ......
  • Qt 将 widget 打印到 pdf
    一开始直接render到QPrinter里发现渲染出的图很小,原因是没有把两者的尺寸对齐到一致这里我们按printer和widget的比例缩放:defexportToPDF(w:QWidget,file_name):printer=QPrinter()printer.setPageSize(QPrinter.A4)printer.setOutputFormat(......
  • C#开发的免费PDF转换、压缩、拆分、合并助手
    《骑士科技星火计划》现推出首款产品—《工程人PDF助手》,为工程人打造属于自己的PDF功能助手,具有PDF转换、压缩、拆分及合并等功能。《工程人PDF助手》为《骑士科技星火计划》首款产品,安装步骤简单,操作便捷,供各位工程人免费使用! 获取方式欢迎关注公众号《工程人的编程课堂》,后......
  • 请求处理类 yii\web\Request
    $request=Yii::$app->request;//请求对象//$request->enableCsrfValidation=false;//取消CSRF验证$resolve=$request->resolve();//请求拆分$getHeaders=$request->getHeaders();//请求头集合$getMethod=$request->getMethod(......