web前端pdf.js预览pdf实例创建报错:Array. prototype` contains unexpected enumerable properties
使用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扩展的第三方库,并且在代码中移除它就可以,这样,问题就被解决了。
Windows 10 专业版下推送docker镜像到harbor报错:x509: certificate relies on legacy Common Name field, use SANs instead
harbor是公司私有镜像仓库,在Windows 10 专业版上安装上docker DeskTop,客户端成功开启之后,就是推送镜像啦。
记得先登录, docker login --username=admin xxx.harbor.com:10443,这个不能忘记!!
在实际推送中遇到了几个问题,下面来看看问题:
1. 问题:Get "xxx.harbor.com:10443/v2/": x509: certificate relies on legacy Common Name field, use SANs instead
x509: certificate relies on legacy Common Name field, use SANs instead
这是证书的问题需要编辑 daemo.json
文件:C:\Users\用户名\.docker\daemon.json
{ "registry-mirrors": [ "https://4etfidgd.mirror.aliyuncs.com"],}
2. 问题:Get "yunli.harbor.com:10443/v2/": http: server gave HTTP response to HTTPS client
Get "xxx.harbor.com:10443/v2/": http: server gave HTTP response to HTTPS client
从1.3.X之后,与docker registry交互默认使用HTTPS,但是搭建私有镜像仓库harbor默认使用HTTP服务,所以与私有镜像仓库交互时出现以上错误。
{ "insecure-registries": ["xxx.harbor.com:10443"] }
添加上以上配置就可以通过http推送啦。