1 回复
你好,云函数 puppeteer 不需要安装,直接 require 使用即可。参考:
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({
args: ['--no-sandbox']
});
const page = await browser.newPage();
await page.goto('https://example.com');
const buf = await page.screenshot();
await browser.close();
return {
event,
buf,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
}
}