2017-12-28 11 views
0

현재 일부 기능을 사용하기 위해 브라우저에서 URL을 열어야하는 응용 프로그램을 빌드해야하는 프로젝트에서 작업 중입니다.
노드 소켓 스크립트에서 puppeteer을 사용하여 서버 측에서 브라우저를 열면 API처럼 사용할 수 있습니다. 여기 heroku에서 헤드리스없이 크롬을 출력하는 동안 발생하는 오류

코드 (nodejs)입니다 :

app.get('/do', (req, res) => { 
    console.log("ok"); 
    (async() => { 
     var browser = await puppeteer.launch(
      { args: ['--no-sandbox','--disable-setuid-sandbox'], headless: false }); 
     var page = await browser.newPage(); 
     await page.goto('https://url.com');//i hid the url for personal reason 
     await page.waitFor(1000); // to wait for 1000ms 
     await page.waitFor('body div'); // to wait for the 'body div' selector in body 
     await page.waitFor(() => Math.random() < 0.5); // to wait for the predicate 
     await page.screenshot({ 
      path: 'public/photo.png' 
     }); 

     await browser.close(); 
     await res.end('<html><head></title></head><body><h1><img src=photo.png ></img></h1></body></html>'); 
    })(); 

}); 

이 코드는 로컬로 작동 내가 Heroku가에 배포 할 때 그러나 그것은 나에게이 오류 보여줍니다

app[web.1]: /send
app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to launch chrome!
app[web.1]: /app/node_modules/puppeteer/.local-chromium/linux-515411/chrome-linux/nacl_helper: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
app[web.1]: [21:21:1228/131735.202176:ERROR:nacl_fork_delegate_linux.cc(316)] Bad NaCl helper startup ack (0 bytes)
app[web.1]:
app[web.1]:
app[web.1]: TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
app[web.1]:
app[web.1]: (node:4) [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.

을하지만 headless: false를 제거하면 그것은 작동하지만 문제는 URL이 크롬이나 모질라 또는 사파리와 같은 브라우저를 사용해야하는 예열 페이지를 보여줍니다.

이 문제를 어떻게 해결할 수 있습니까?

답변

0

앱의 빌드 팩 목록에 Puppeteer Heroku 빌드 팩을 포함시켜야합니다. Heroku dashboard으로 이동하여 앱을 엽니 다. 설정> 빌드 팩> 빌드 팩 추가로 이동하여이 URL을 사용하십시오.

https://github.com/jontewks/puppeteer-heroku-buildpack 

buildpack 추가를 클릭하면 해당 URL을 입력에 붙여넣고 저장을 클릭하면됩니다. 다음 배포시, 앱은 Puppeteer가 실행해야하는 종속성도 설치합니다.

Puppeteer on Heroku

더 많은 도움을 troubleshooting guide를 참조하십시오.

관련 문제