I have a page with several book covers and a button to download them all.
Book covers are in String format and are a Google Books URL. I'm populating like this:
<section ref="capture" id="my-node">
<figure v-for="book in books" :key="book.id">
<img :src="book.thumbnail" :alt="`Book ${book.title}`" />
</figure>
<button type="button" @click="download">html2canvas</button>
</section>
To download the book covers I'm calling the following function:
download() {
html2canvas(this.$refs["capture"], { allowTaint: true })
.then((canvas) => {
let link = document.createElement("a");
link.download = "Livrero.png";
link.href = canvas.toDataURL("image/png");
link.click();
})
},
Books is an object that contains a thumbnail
property with values like this: https://books.google.com/books/content?id=_i6bDeoCQzsC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api
What makes me more confused is that if I were using values similar to this: https://images-na.ssl-images-amazon.com/images/I/41xShlnTZTL._SX218_BO1,204,203,200_QL40_FMwebp_.jpg
everything would be working, but unfortunately the project does not allow this at the moment.
Previously I was using the property useCORS: true
in html2canvas
however it was returning a CORS policy error. So, when I removed it, I stopped having this error and started getting the following error:
DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement':
Tainted canvases may not be exported.
It was suggested that I use http://html2canvas.hertzen.com/proxy/ to succeed in the mission, but because I'm using Vue.js I don't know how to apply this.