收藏
回答

请问云函数不可以使用puppeteer么?

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

回答关注问题邀请回答
收藏

1 个回答

  • Shannon
    Shannon
    2021-04-29

    你好,云函数 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,
      }
    }
    
    2021-04-29
    有用
    回复 6
    查看更多(1)
登录 后发表内容