I am running using Docker and docker-compose to run a NodeJS scrapper with puppeteer. My troubleshooting is as follows:
EXPECTED OUTPUT: Im getting the title page from wikepedia
CASE 1: When running function1() with await the process stops
OUTPUT:
Browser is running
//console.log("function1() end" ) does not execute
Case2: If function1() has no await the function does not execute but the console.log after is executed
OUTPUT:
Browser is running
function1() end
How can I run the function1 using await and get the title of page output.
async function function1() {
let page = await browser.newPage()
await page.setUserAgent(
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36',
)
await page.goto(
'https://en.wikipedia.org/wiki/Main_Page',
{
waitUntil: 'networkidle2',
},
)
console.log(await page.title())
}
async function looper() {
await function1()
await console.log('function1 end')
}
async function startPuppeteer() {
browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
})
console.log('Browser is running')
setInterval(looper, 30000)
}
Dockerfile
FROM buildkite/puppeteer:latest
USER root
COPY . /app
RUN cd /app && npm install
EXPOSE 8000
WORKDIR /app
CMD npm run start
Docker-compose.yml
version: "3.9"
services:
web:
build: .
ports:
- "8000:8000"