G33kDude / Chrome.ahk

Automate Google Chrome using native AutoHotkey
https://autohotkey.com/boards/viewtopic.php?t=42890
MIT License
340 stars 83 forks source link

Hangs on while !this.responses[ID] #16

Open kimpurcell opened 4 years ago

kimpurcell commented 4 years ago

Have a script that runs every 15 minutes. Stops working after a while and saw that it's hung on ; Wait for the response this.responses[ID] := False while !this.responses[ID] Sleep, 50

G33kDude commented 3 years ago

Where it says

; Use a temporary variable for ID in case more calls are made
; before we receive a response.
ID := this.ID += 1
this.ws.Send(Chrome.Jxon_Dump({"id": ID
, "params": Params ? Params : {}
, "method": DomainAndMethod}))

if !WaitForResponse
    return

; Wait for the response
this.responses[ID] := False
while !this.responses[ID]
    Sleep, 50

can you change it to say

; Use a temporary variable for ID in case more calls are made
; before we receive a response.
ID := this.ID += 1

if WaitForResponse
    this.responses[ID] := False

this.ws.Send(Chrome.Jxon_Dump({"id": ID
, "params": Params ? Params : {}
, "method": DomainAndMethod}))

if !WaitForResponse
    return

; Wait for the response
while !this.responses[ID]
    Sleep, 50

and see if that works any better?

kimpurcell commented 3 years ago

Thanks, testing it now and will let you know...

kimpurcell commented 3 years ago

It works for a little while, then goes into an infinite loop on Sleep.

Here's the log:

279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.05) 279: While,!this.responses[ID] 280: Sleep,50 (0.02)

dmtr99 commented 3 years ago

May I propose a solution? My theory is that the Call at some occasions is not recieved by chrome. So It would be logically to repeat the call.

  1. Moving [this.responses[ID] := False] before the Send Seems logically and during some tests I performed, I had the impression there where less errors. They still occured, but I not anymore in the Evaluate function.
  2. Goto function if the wait is to long. If you want you can activate het Message box to indicate if the script got stuck, or exit the thread if this is acceptable.

Please test this and let me know your experiences.

; Use a temporary variable for ID in case more calls are made
; before we receive a response.
ChromeRepeat:
ID := this.ID += 1
this.responses[ID] := False
this.ws.Send(Chrome.Jxon_Dump({"id": ID
, "params": Params ? Params : {}
, "method": DomainAndMethod}))

if !WaitForResponse
    return

; Wait for the response
;~ this.responses[ID] := False
while !this.responses[ID]
{
    Sleep, 50
    if (A_Index=50){
        ; MsgBox, Error
        Goto, ChromeRepeat
        return 0
    }
}