# Puppeteer test ## Installation ```bash $ npm i puppeteer added 105 packages in 14s 11 packages are looking for funding run `npm fund` for details $ npx puppeteer --help puppeteer Commands: puppeteer browsers Manage browsers of this Puppeteer installation Options: --version Show version number [boolean] --help Show help [boolean] $ npx puppeteer browsers puppeteer browsers Manage browsers of this Puppeteer installation Commands: puppeteer browsers install [browser] Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: @ ). puppeteer browsers launch Launch the specified browser puppeteer browsers clear Removes all installed browsers from /Users/shinyu/.cache/puppeteer puppeteer browsers list List all installed browsers in the cache directory Options: --version Show version number [boolean] --help Show help [boolean] Not enough non-option arguments: got 0, need at least 1 $ npx puppeteer browsers install firefox Downloading firefox stable_134.0 - 154.9 MB [====================] 100% 0.0s firefox@stable_134.0 /Users/shinyu/.cache/puppeteer/firefox/mac_arm-stable_134.0/Firefox.app/Contents/MacOS/firefox $ npx puppeteer browsers launch firefox node:events:502 throw er; // Unhandled 'error' event ^ Error: spawn /Users/shinyu/.cache/puppeteer/firefox/mac_arm-pinned/Firefox Nightly.app/Contents/MacOS/firefox ENOENT at ChildProcess._handle.onexit (node:internal/child_process:285:19) at onErrorNT (node:internal/child_process:483:16) at process.processTicksAndRejections (node:internal/process/task_queues:90:21) Emitted 'error' event on ChildProcess instance at: at ChildProcess._handle.onexit (node:internal/child_process:291:12) at onErrorNT (node:internal/child_process:483:16) at process.processTicksAndRejections (node:internal/process/task_queues:90:21) { errno: -2, code: 'ENOENT', syscall: 'spawn /Users/shinyu/.cache/puppeteer/firefox/mac_arm-pinned/Firefox Nightly.app/Contents/MacOS/firefox', path: '/Users/shinyu/.cache/puppeteer/firefox/mac_arm-pinned/Firefox Nightly.app/Contents/MacOS/firefox', spawnargs: [] } Node.js v22.12.0 ``` ## Test ### test-headed.js ```js import puppeteer from 'puppeteer'; const browser = await puppeteer.launch({ headless: false, }); const page = await browser.newPage(); await page.goto('https://gist.githack.com/anghenfil/4a7635e45c900e636561d93756ac0b66/raw/test.html'); ``` ### test-pdf.js ```js import puppeteer from 'puppeteer'; const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://gist.githack.com/anghenfil/4a7635e45c900e636561d93756ac0b66/raw/test.html'); await page.pdf({path: 'output.pdf', width: '210mm', height: '297mm'}); await browser.close(); ``` ### test-headed-firefox.js ```js import puppeteer from 'puppeteer'; const browser = await puppeteer.launch({ browser: 'firefox', headless: false, }); const page = await browser.newPage(); await page.goto('https://gist.githack.com/anghenfil/4a7635e45c900e636561d93756ac0b66/raw/test.html'); ``` ### test-pdf-firefox.js ```js import puppeteer from 'puppeteer'; const browser = await puppeteer.launch({ browser: 'firefox', }); const page = await browser.newPage(); await page.goto('https://gist.githack.com/anghenfil/4a7635e45c900e636561d93756ac0b66/raw/test.html'); await page.pdf({path: 'output.pdf', width: '210mm', height: '297mm'}); await browser.close(); ```