node.js - Puppeteer bot works locally but fails to click button Kubernetes - Stack Overflow

I have a Teams meeting bot using Puppeteer that works perfectly fine locally but fails when deployed to

I have a Teams meeting bot using Puppeteer that works perfectly fine locally but fails when deployed to Kubernetes. The bot get stuck and can not click on the button even though it found that button.

Quesitons:

  1. What could cause this behavior difference between local and Kubernetes environments?

  2. Are there specific Puppeteer configurations needed for Kubernetes deployments?

  3. Could this be related to network idle or page load states?

Code Structure:

class Task {
  async initMeeting() {
    const { meetingUrl, userName } = this.taskData;

    await this.page.goto(meetingUrl, {
      waitUntil: 'load',
      timeout: 0,
    });


    await this.enterUserNameAndJoin(userName);
  }
   
    async ensurePageReloaded() {
        await Promise.all([
          this.page.reload(),
          waitForNetworkIdle(this.page, 1_000, 2),
        ]);
      }

    
  async enterUserNameAndJoin(userName) {
    const nameToType = `${userName}'s Assistant`;
    const selector = '[data-tid="prejoin-display-name-input"]';
    
    await this.page.waitForSelector(selector, {
      visible: true,
      timeout: 10000
    });

    await typeInput(this.page, {
      value: nameToType,
      dataTid: 'prejoin-display-name-input',
    });

    await this.page.waitForTimeout(1000);
    await clickButton(this.page, { ariaLabel: 'Join now' });
  }

}

My waitForNetWorkIdle

const waitForNetworkIdle = (page, timeout, maxInflightRequests = 0) => {
  page.on('request', onRequestStarted);
  page.on('requestfinished', onRequestFinished);
  page.on('requestfailed', onRequestFinished);

  let inflight = 0;
  let fulfill;
  let promise = new Promise((x) => (fulfill = x));
  let timeoutId = setTimeout(onTimeoutDone, timeout);
  return promise;

  function onTimeoutDone() {
    page.removeListener('request', onRequestStarted);
    page.removeListener('requestfinished', onRequestFinished);
    page.removeListener('requestfailed', onRequestFinished);
    fulfill();
  }

  function onRequestStarted() {
    ++inflight;
    if (inflight > maxInflightRequests) clearTimeout(timeoutId);
  }

  function onRequestFinished() {
    if (inflight === 0) return;
    --inflight;
    if (inflight === maxInflightRequests)
      timeoutId = setTimeout(onTimeoutDone, timeout);
  }
};

What I've Tried:

Increased timeouts Added delays between actions Verified network connectivity Checked for element visibility

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745606310a4635693.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信