G33kDude / Chrome.ahk

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

Stuck at sleep loop #11

Open sergiobachega opened 5 years ago

sergiobachega commented 5 years ago

Sometimes, the return of this.ws.Send on line 233 is so fast that that execution gets line 320 before line 241. ID not exists on responses list, so it get stucked on 242 loop.

232 ID := this.ID += 1 233 this.ws.Send(Chrome.Jxon_Dump({"id": ID 234 , "params": Params ? Params : {} 235 , "method": DomainAndMethod})) 236
237 if !WaitForResponse 238 return 239
240 ; Wait for the response 241 this.responses[ID] := False 242 while !this.responses[ID] 243 Sleep, 50

315 ; Run the callback routine 316 fnCallback := this.fnCallback 317 if (newData := %fnCallback%(data)) 318 data := newData 319
320 if this.responses.HasKey(data.ID) 321 this.responses[data.ID] := data

The solution is to transfer "this.responses[ID] := False" to before "this.ws.Send"

232 ID := this.ID += 1 233 if WaitForResponse 234 this.responses[ID] := False 235 this.ws.Send(Chrome.Jxon_Dump({"id": ID 236 , "params": Params ? Params : {} 237 , "method": DomainAndMethod})) 238
239 if !WaitForResponse 240 return 241 ; Wait for the response 242 while !this.responses[ID] 243 Sleep, 50

StavenCross commented 4 years ago

I'm also struggling with this. Any time I execute a call to the page outside my origional connection call, i end up in an endless loop.

However, I tried the above fix, and that didn't work.

This is most noteable when I use AHK to evaluate JS on the page or issue a Call to change the url

such as: navigator(url) { global wb ;bring in our PageInst

wb.Call("Page.navigate", {"url": "" . url . ""}) ; navigate to new URL and we get stuck in a sleep loop.
J-Filip commented 3 years ago

Has anyone found solution for this? It seems like it only goes to sleep loop if chrome is left untouched. So it probably loses connection to chrome instance. I tried fixing it but it just goes to loop after couple of minutes.

Is there a way at least to catch it and reload or something simillar?

gabrigrillo commented 2 years ago

is there any news about this issue?