我在Replit中托管我的不和谐机器人。并且,我使用node-html-to-image包将html转换为jpeg。当我在localhost中尝试它时,它工作得很好。但当我在Replit中尝试它时,它返回以下错误:
(node:250) UnhandledPromiseRejectionWarning: Error: Unable to launch browser, error message: Failed to
launch the browser process!下面是我使用的代码htmltoPng.js
const { MessageAttachment } = require("discord.js");
const nodeHtmlToImage = require("node-html-to-image");
const puppeteer = { args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-accelerated-2d-canvas', '--no-first-run', '--headless', '--no-zygote', '--disable-gpu'], headless: true, ignoreHTTPSErrors: true };
module.exports = async (msg, user, data) => {
const _htmlTemplate = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<style>
body {
font-family: "Poppins", Arial, Helvetica, sans-serif;
background: rgb(22, 22, 22);
color: #fff;
max-width: 300px;
}
.app {
max-width: 300px;
padding: 20px;
display: flex;
flex-direction: row;
border-top: 3px solid rgb(16, 180, 209);
background: rgb(31, 31, 31);
align-items: center;
}
img {
width: 50px;
height: 50px;
margin-right: 20px;
border-radius: 50%;
border: 1px solid #fff;
padding: 5px;
}
</style>
</head>
<body>
<div class="app">
<img src="${user.username}" />
<h4>Welcome ${msg.author.username}</h4>
</div>
</body>
</html>
`;
const images = await nodeHtmlToImage({
html: _htmlTemplate,
quality: 100,
type: "jpeg",
puppeteerArgs: puppeteer,
});
return msg.channel.send(new MessageAttachment(images, `${name}.jpeg`));
};任何帮助都是非常感谢的!
谢谢!
发布于 2021-05-10 15:29:37
您在这里的目标是创建一张欢迎卡片,然后将其张贴到通道中,对吧?为什么不使用canvas,它更快更高效呢?网上甚至有专门针对不和谐的指南:
https://discordjs.guide/popular-topics/canvas.html#setting-up-canvas
祝你编码愉快!
发布于 2021-06-08 02:52:14
问题
包node-html-to-image当前使用的是pupeteer 3.0.0,它不包含所有必需的依赖项。此问题已在pupeteer 3.0.4中修复。
解决方案
您可以在等待程序包更新时安装必要的依赖项。
sudo apt-get install -y libgbm-dev
链接
以下是node-html-to-image https://github.com/frinyvonnick/node-html-to-image/issues/91的问题
下面是关于pupeteer端https://github.com/actions/virtual-environments/issues/732#issuecomment-614809415的问题
更新
拉取请求已被接受。node-html-to-image v3.2.0应该可以为您工作。
https://stackoverflow.com/questions/67444649
复制相似问题