我正在尝试使用 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)