raspberry pi 에서 puppeteer 사용하기!
본격적으로 raspberry pi에서 개발을 하고 있다.
기존 개인 프로젝트 중에서 puppeteer를 사용한 프로젝트를 수정하려는데, 동작은 하지 않고 다음과 같은 오류가 발생했다.
> request-book-library@1.0.0 start /home/pi/DEV/99.personal/request-book-library
> node index.js
(node:3745) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
/home/pi/DEV/99.personal/request-book-library/node_modules/puppeteer/.local-chromium/linux-672088/chrome-linux/chrome: 2: /home/pi/DEV/99.personal/request-book-library/node_modules/puppeteer/.local-chromium/linux-672088/chrome-linux/chrome: Syntax error: Unterminated quoted string
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
at onClose (/home/pi/DEV/99.personal/request-book-library/node_modules/puppeteer/lib/Launcher.js:340:14)
at Interface.helper.addEventListener (/home/pi/DEV/99.personal/request-book-library/node_modules/puppeteer/lib/Launcher.js:329:50)
at Interface.emit (events.js:203:15)
at Interface.close (readline.js:397:8)
at Socket.onend (readline.js:173:10)
at Socket.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1129:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:3745) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3745) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
오류가 발생할 문제가 전혀 없음에도 발생하여 당황하며 검색하였지만, 해당 문제는 나오지 않았다.
혹시나 하여 raspberry puppeteer로 검색을 하니 다음 글을 찾았다.
Chrome Headless and Puppeteer on Raspberry Pi
해당 글을 참고로 puppeteer-core를 설치하여 테스트 하니 아주 잘된다.
sudo apt install chromium-browser chromium-codecs-ffmpeg
sudo install npm
npm install puppeteer-core@v1.11.0
const puppeteer = require(‘puppeteer-core’);
const browser = await puppeteer.launch({executablePath: ‘/usr/bin/chromium-browser’});
os가 비슷하지만 다르기 때문인지 동작이 조금식 다르다.