Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling of disconnected browser #11

Open
moaoci opened this issue Jul 5, 2022 · 2 comments
Open

Error handling of disconnected browser #11

moaoci opened this issue Jul 5, 2022 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@moaoci
Copy link
Contributor

moaoci commented Jul 5, 2022

The error ( halt to the STOP instruction ) occurs when the browser is manually disconnected while the user macros are running. Might also happen if www site returns a time out.

Mine occurs in AutomateBrowser.querySelectorAll, (other functions might be also be affected.)

ErrHandler:
Debug.Print "AutomateBrowser.querySelectorAll - " & Err.description
Stop
Resume
End Function

The RESUME after the STOP will rapidly bring back to the STOP and on and on.

The documentation says «' Note: resulting Dictionary will be empty (0 items) if an error or no matching elements found»

Changing RESUME to RESUME NEXT seems to work, returning 0 items as stated.

After returning 0 items, is there a way to verify if browser is unavailable or if querySelectorAll simply did not find anything ? If so, the STOP could also be removed.

I am not at ease with the whole AutomateBrowser module. Other ErrHandler: simply stop before end function, no resume. Can someone verify ?

@PerditionC
Copy link
Owner

The error handling needs improving. Currently it is just setup for debugging issues, does not handle disconnection well. There are a few ways I can implement this, but I'm not sure what is the best. I can have the function return 0 items and set the global error variable to a value for error, e.g. disconnected. Or I can have the call throw the error - letting higher up calls see and handle the error. I don't want to just ignore the error (which is really what the resume and resume next would do), but I'm not sure the best way to communicate it to the caller. So far I'm thinking adding an error or disconnected function to AutomateBrowser class. Then add a check so before making the CDP call to the browser check if still connected and either fail or perhaps try reconnecting first then fail if not connected/other error. I'm open to suggestions - just throw error to caller or handle it and internally note error occurred?

@PerditionC PerditionC added enhancement New feature or request question Further information is requested labels Jul 5, 2022
@tonton81
Copy link

tonton81 commented Sep 12, 2023

i use on error goto xxxx in vba, since it polls the code randomly, a disconnected browser wont cause an exception to be thrown in vba. at the same time you can have your function return a response like "ERROR" or "SUCCESS" so your other code can process the payload if it was successful.

IMHO the error handling should be done by the user like i did above, because in either case the user would still need to identify whether the library was a success or not before processing the request..., and at the same time if there are errors without the goto call it's easy to debug what caused it.

so in my function a successful transaction function returns "SUCCESS", and if the link to chrome was broken "ERROR" is returned via goto. So upon receiving a "SUCCESS" (my function would for example dump the page to a hidden sheet), the sheet would be processed. if an ERROR was returned, code wouldnt execute the hidden sheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants