Puppeteer PDF 导出不呈现图像

Puppeteer PDF export doesn't render images

我尝试将我的 HTML 导出到一个 pdf 文件,该文件工作正常,但我的图像未加载。 当我使用 headless: false 选项时,我看到加载了图像的网站,但是当我导出 PDF 时,图像只是未加载图像的默认图标:

我的代码:

  const browser = await puppeteer.launch({ headless: false, args: ["--explicitly-allowed-ports=" + port] });
  const page = await browser.newPage();
  await page.setContent(content, { waitUntil: "networkidle0" }); // I also tried "load"
  await page.waitFor(2000); // The page should be loaded for sure
  await page.emulateMediaType("print");
  await page.pdf({ path: "F:\Desktop\file.pdf", format: "a4" });
  await browser.close();

我已经尝试了媒体类型“屏幕”和“打印”,但都不起作用。网页的HTML为:

<html xmlns="http://www.w3.org/1999/xhtml">
   <head></head>
   <body>
      <p>Es handelt sich hierbei um ein File:</p>
      <p><strong>File:</strong></p>
      <sm-file class="mceNonEditable" title="Bright Solutions _ Digitale Projekt-Checklisten.pdf" data-uuid="AD13E638-6DB5-4DCD-A7F6-03D66C1D24DF" data-name="Bright Solutions _ Digitale Projekt-Checklisten.pdf">
         <img src="http://localhost:6666/icon_file.svg" width="20px" height="20px" />
         <hr />
         Bright Solutions _ Digi... ten.pdf
      </sm-file>
      <p>Hier kommt dann noch ein Bild hinzu!</p>
   </body>
</html>

有谁知道我该怎么做才能正确呈现 PDF 中的图像?

原因是ERR_UNSAFE_PORT!端口 6666 被认为是不安全的。可以在此处查看不安全端口的完整列表:https://superuser.com/questions/188058/which-ports-are-considered-unsafe-by-chrome 所以只需将网络服务器的端口更改为不在此列表中的端口即可,一切正常。