请问云函数不可以使用puppeteer么?
发布于 4 年前 作者 zengwei 2038 次浏览 来自 官方Issues

请问云函数不可以使用puppeteer么?试了很多遍,一直不行

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,
  }
}
回到顶部