I’m trying to join msTeams meeting but the “Join now” button doesn’t get clicked when I deploy the changes on an EC2 instance, but it works fine locally. When I added a few Screenshots, it’s visible that the button actually gets focused, it’s just not getting clicked.
const puppeteer = require("puppeteer-extra");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
puppeteer.use(StealthPlugin());
function startMeeting() {
const browser = await puppeteer.launch({
headless: false,
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
],
ignoreDefaultArgs: ["--mute-audio"],
executablePath: executablePath("chrome"),
ignoreHTTPSErrors: true
});
const page = await browser.newPage();
const navigationPromise = page.waitForNavigation();
await page.goto(link, {
waitUntil: "domcontentloaded",
});
await navigationPromise;
// More logic
await page.waitForSelector('button[aria-label="Join now"]');
await new Promise(r => setTimeout(r, 1 * 1000));
await page.focus('button[aria-label="Join now"]');
await page.click('button[aria-label="Join now"]'); // This part is not working on EC2
}
My Dockerfile
# Use Node.js official image as the base image
FROM node:latest
# Set working directory inside the container
WORKDIR /usr/src/app
ENV DISPLAY=:99
# Copy package.json and package-lock.json (if available)
COPY package*.json ./
# Install dependencies
RUN npm install
# Install Google Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
&& apt-get update && apt-get install -y google-chrome-stable
# Install Puppeteer dependencies
RUN apt-get update && apt-get install -y
wget
gnupg
ca-certificates
procps
libxshmfence1
libgbm1
libasound2
libatk-bridge2.0-0
libatspi2.0-0
libgtk-3-0
libnss3
libx11-xcb1
libxcomposite1
libxdamage1
libxfixes3
libxrandr2
xvfb
# Copy the rest of the application code
COPY . .
RUN chmod +x /usr/src/app/entrypoint.sh
# Expose port 3000
EXPOSE 3000
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
# Command to run the application
CMD ["node", "app.js"]
entrypoint.sh
#!/bin/sh
# Start Xvfb
Xvfb :99 -screen 0 1280x720x24 -ac & npm run test
export DISPLAY=:99
exec "$@"
This code is working fine on local but just not on EC2
Packages:
"puppeteer": "^22.11.0",
"puppeteer-extra": "^3.3.6",
"puppeteer-extra-plugin-stealth": "^2.11.2"
I have tried multiple ways to click the button but none has worked so far
1.
await page.evaluate(() => {
const element = document.querySelector('button[aria-label="Join now"]')
element.click()
})
page.$eval('button[aria-label="Join now", element =>
element.click()
)
I’m unsure if it’s a Puppeteer issue as the code is working fine on local. I have also tried to update my Dockerfile by adding more packages but nothing worked. At this point I’m even considering to switch Puppeteer with some other Automation method.
Any help or suggestion is greatly appreciated. Thank you so much, have a good day!
Anil kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.