几年之前用puppeteer做过网站测试、手机短信攻击、爬虫,但是一直没有记录,都忘记了,重新记录下
1、通过输入chrome://version/,查看chrome安装位置
2、npm i puppeteer
import puppeteer from 'puppeteer-core' (async () => { const userAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1" const browser = await puppeteer.launch({ args: [`--user-agent=${userAgent}`], headless: false, 'executablePath':'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' }); const page = await browser.newPage(); page.setUserAgent(userAgent) page.setViewport({ width:390, height:844, }) await page.goto('https://example.com'); await page.screenshot({ path: 'example.png' }); await browser.close(); })();
标签:浏览器,chrome,await,puppeteer,mac,userAgent,page,const From: https://www.cnblogs.com/caoke/p/18342371