如何使用Node.js使用puppeter等待传入消息?

如何使用Node.js使用puppeter等待传入消息?,node.js,puppeteer,Node.js,Puppeteer,这是在循环中发送自动消息的代码。如何等待新消息,然后发送消息 let scrape = async (url)=>{ //scraping function const browser = await puppeteer.launch({headless:false}); const page= await browser.newPage(); await page.goto(url);

这是在循环中发送自动消息的代码。如何等待新消息,然后发送消息

let scrape = async (url)=>{                                         //scraping function
    const browser = await puppeteer.launch({headless:false});
    const page= await browser.newPage();
   await  page.goto(url);
    await page.waitForSelector("span[title='xyz']");

   const target=await page.$("span[title='xyz']");      //selecting target user

  await  target.click();
    const inp=await page.$("#main > footer > div._3ee1T._1LkpH.copyable-area > div._3uMse > div > div._3FRCZ.copyable-text.selectable-text");
    for(let i=0;i<2;i++){
        inpMessage();              //input message details        
       
    }

}

function inpMessage(){                 //input message function call
    await inp.type("hi");
       
        await page.keyboard.press("Enter");
}

scrape('https://web.whatsapp.com/');         //function call```
let scrap=async(url)=>{//scrap函数
const browser=wait puppeter.launch({headless:false});
const page=wait browser.newPage();
等待页面。转到(url);
等待page.waitForSelector(“span[title='xyz']”);
const target=wait page.$(“span[title='xyz']);//选择目标用户
等待目标。单击();
const inp=wait page.$(“#main>footer>div."可复制文本."1LkpH.copyable-area>div."可复制文本."div;

for(设i=0;i生成
inpMessage
函数
async
函数,并在for循环中等待
inpMessage
函数。但我想等待传入消息(来自前端的消息)