最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论