ok what @water said, is the right way. ...also, and just for the record... if you don't want to use something like ObjEvent ("AutoIt.Error", ...) there is also another "quick and dirty" workaround to avoid crashes that I've seen used by @genius257 here: https://www.autoitscript.com/forum/topic/185387-value-of-js-variable-in-ie/?do=findComment&comment=1332372 and explained here: https://www.autoitscript.com/forum/topic/185387-value-of-js-variable-in-ie/?do=findComment&comment=1332585
in short you could wrap your "$oIE.document.parentWindow.location.href" (or whatever) in an Execute() statement and check for errors right after the call, that way you can see if something went wrong without a "crash", something like this:
$vResult = Execute('$oIE.document.parentWindow.location.href')
If @error Then Exit MsgBox(0, 'sorry', '...something went wrong.')