How many of you run into following error? while making new chrome instance very first time after starting PC,
(
ChromeInst := new Chrome( A_ScriptDir "\ChromeProfile")) and then you reload script and re-create
ChromeInst and it work without any issue, its only one time case after starting PC,
please tell me coz I really wana know about it...!
So what is going on above?:
As far as I know...... When we create
ChromeInst := new Chrome( A_ScriptDir "\ChromeProfile") chrome create 1 process
chrome.exe (we can check it in task manager) and after that, chrome try to create
New tab by putting few more
chrome.exe as processes and we know chrome setting up debugging ip and port ( if you using chrome.ahk you can find it all in there), but very first time chrome takes time (idk why its only for first time), and thats where we/I face above error because chrome haven't created that
TAB,
thats only my theory not fact chrome dev know more about it
Everyday I have faced above error, I know I gonna face this error running chrome.ahk when ever I make first
ChromeInst after starting PC,
idk this happened to y'all or its only with me, So, I have studied it for weeks and came up with a solution which worked,
Code: Select all
ChromeInst := new Chrome( A_ScriptDir "\ChromeProfile")
WaitforNewChromeProcess() ; all this is doing waiting for new TAB to be created by counting chrome.exe processes
and you can test it something like this, and I was surprised my above theory was correct
Code: Select all
s := ChromeProcessCount()
ChromeInst := new Chrome( A_ScriptDir "\ChromeProfile")
r := WaitforNewChromeProcess()
msgbox, % "Chrome.exe process count:`nBefore creating instance:" s "`n" r
return
WaitforNewChromeProcess(sleep=500)
{
i := n := ChromeProcessCount()
while (n = i)
{
sleep, % sleep
i := ChromeProcessCount()
}
return "after creating instance:" n "`nAfter Creating new Tab:" i
}
ChromeProcessCount()
{
n := 0
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
if( process.Name = "Chrome.exe")
++n
return n
}
and thats my result
Hope y'all find this useful, and its common sense while
WaitforNewChromeProcess if you close any chrome tab (any mean every chrome tab both created with chrome.ahk or User), above code stop gonna wait and you might face error
if anyone having same issue please tell me if
WaitforNewChromeProcess worked you too?
I should have named this function something like
WaitForChromeProcessChange or
wfcpc