小编Isr*_*ins的帖子

我无法在 heroku 中使用 puppeteer 进行截图

我正在尝试使用 heroku 服务器中的 puppeteer 将屏幕截图应用程序用于我的投资组合。

服务器.js

(async() => {
        const browser = await puppeteer.launch({
            args: ['--no-sandbox', '--disable-setuid-sandbox']
        });

        const page = await browser.newPage();

        await page.goto(urlToScreenshot,{timeout:60000});

        await page.waitFor(3000);


        await page.screenshot().then(function(buffer) {
            res.setHeader('Content-Disposition', 'attachment;filename="' + urlToScreenshot + '.png"');
            res.setHeader('Content-Type', 'image/png');
            res.send(buffer);
        });

        await browser.close();
    })();
Run Code Online (Sandbox Code Playgroud)

测试截图.html

<div>

   <img class="port container-fluid lazy" style="height:226px;" src="https://url2screenshot-imm.herokuapp.com/?url=https://google.com/">

   <img class="port container-fluid lazy" style="height:226px;" src="https://url2screenshot-imm.herokuapp.com/?url=https://yahoo.com/">

   <img class="port container-fluid lazy" style="height:226px;" src="https://url2screenshot-imm.herokuapp.com/?url=https://facebook.com/">

   <img class="port container-fluid lazy" style="height:226px;" src="https://url2screenshot-imm.herokuapp.com/?url=https://twitter.com/">

   <img class="port container-fluid lazy" style="height:226px;" src="https://url2screenshot-imm.herokuapp.com/?url=https://reddit.com/">

   <img class="port container-fluid lazy" style="height:226px;" …
Run Code Online (Sandbox Code Playgroud)

html javascript heroku node.js puppeteer

3
推荐指数
1
解决办法
1466
查看次数

标签 统计

heroku ×1

html ×1

javascript ×1

node.js ×1

puppeteer ×1