实时网页截图

问题描述 投票:0回答:0

我正在尝试截取远程网页/外部域使用

html2canvas

我的代码

var url = "https://example.com"; // Replace with the URL of the webpage you want to screenshot
var options = {
  useCORS: true,
  allowTaint: true,
  scrollX: 0,
  scrollY: 0,
  width: window.innerWidth,
  height: window.innerHeight,
};
html2canvas(document.body, options).then(canvas => {
  // `canvas` is the screenshot of the webpage, represented as a canvas element
  // You can append the canvas to the document or export it as an image:
  document.body.appendChild(canvas);
  // To export the screenshot as an image file:
  var link = document.createElement("a");
  link.download = "screenshot.png";
  link.href = canvas.toDataURL();
  link.click();
}).catch(error => {
  console.error(error);
});
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>

这段代码成功地截取了这个脚本的网页截图,而不是外部域的截图

example.com

我该如何解决?

javascript html jquery canvas html2canvas
© www.soinside.com 2019 - 2024. All rights reserved.