My task is to wind the number of people online on the website using a bot. Conditions: 1. The bot should go to the site and stay on this page as long as possible (do not break the connection) 2. The site can use both - WebSockets or long polling to check the connection (ie, javascript should be supported)
I have a solution with headless browser(puppeteer) + node.js
const puppeteer = require('puppeteer');
async function runBot(botsCount = 10, secondsToWait = 60, interval = 1000) {
let time = secondsToWait * 1000;
console.log(`Starting chrome...`);
const browser = await puppeteer.launch({
args: [
'--disable-gpu',
'--no-sandbox',
'--headless',
'--disable-web-security',
'--disable-dev-profile',
'--disable-dev-shm-usage',
]
})
for (let i = 1; i <= botsCount; i++) {
const page = await browser.newPage();
await page.goto('https://www.example.page/');
console.log(`Page ${i} created`);
}
console.log(`Awaiting for finish...`);
const savedInterval = setInterval(() => {
process.stdout.write("\rTime Left:" + (time / 1000) + " ");
time -= interval;
if(time === 0) {
clearInterval(savedInterval);
browser.close();
console.log(`\nFinished`);
}
}, interval);
}
runBot();
But this is not a very good solution since each browser window uses from 60MB to 120MB of RAM. It's very expensive...
Perhaps someone has come across this and knows some solutions, how to do it more efficiently?
Any help appreciated