puppet-wechat icon indicating copy to clipboard operation
puppet-wechat copied to clipboard

a PR about issue #230

Open zinsserzc opened this issue 10 months ago • 2 comments

I am using wechaty on my Mac Pc and I run into the error below.

16:52:32 ERR PuppetWeChatBridge start() exception: TimeoutError: Navigation timeout of 60000 ms exceeded
16:52:32 SILL StateSwitch <PuppetWeChatBridge> inactive() is false
16:52:32 VERB StateSwitch <PuppetWeChatBridge> inactive(true) <- (false)
16:52:32 ERR PuppetWeChat initBridge() exception: Navigation timeout of 60000 ms exceeded
16:52:32 VERB PuppetWeChatBridge stop()
16:52:32 SILL StateSwitch <PuppetWeChatBridge> inactive() is true
16:52:32 VERB StateSwitch <PuppetWeChatBridge> inactive(pending) <- (true)
16:52:32 WARN PuppetWeChatBridge stop() page.close() exception: Error: Protocol error: Connection closed. Most likely the page has been closed.
16:52:32 SILL PuppetWeChatBridge stop() browser.close()-ed
16:52:32 SILL StateSwitch <PuppetWeChatBridge> inactive() is pending
16:52:32 VERB StateSwitch <PuppetWeChatBridge> inactive(true) <- (pending)

I have checked the issues and find https://github.com/wechaty/puppet-wechat/issues/230 has the same situation. So I analyzed the start process of this puppet, and I assume the polling request on wx.qq.com prevents the page.goto() from reaching the 'load' state. I tested myself by using puppeteer to open 'wx.qq.com' and the page cannot reach the state of 'load'.
As a result, I tried to modify two parts of the code Bridge.ts about the waiting state of the Puppeteer.Page of opening the url 'wx.qq.com'. And it works.


[!IMPORTANT] Fix navigation timeout in PuppetWeChatBridge by using networkidle2 and changing load event listener to domcontentloaded in bridge.ts.

  • Behavior:
    • Fix navigation timeout in initPage() in bridge.ts by setting waitUntil: 'networkidle2' in page.goto().
    • Change page load event listener from load to domcontentloaded in initPage() to handle polling requests on wx.qq.com.

This description was created by Ellipsis for 9e4df4f0f1a8ea5c9710e2078f1349c61486826d. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features
    • Improved page loading behavior by ensuring navigation waits for the network to be idle.
    • Updated event listener to respond to the domcontentloaded event for better control during page initialization.

zinsserzc avatar Dec 26 '24 09:12 zinsserzc