Browser

CallOnFail: Deciding About a Failure

CallOnFail(CallOnFailDelegate) registers a handler called when something fails that a workflow could reasonably want to decide about. The handler receives the browser, a GPALFailure saying what kind of failure it was, and a detail string. Today the only kind raised is GPALFailure.Navigation, for a GoTo that never loaded a page, with the detail carrying the url and whatever the engine said about it. The handler returns a CallIfStatus: Handled to carry on, Terminate to end the workflow. Setting it on a browser covers that browser; GPAL.CallOnFail sets the fallback for any browser that has none of its own.

NOTE

GPALFailure is an enum with room in it, currently None and Navigation. Switch on it rather than assuming every call is a navigation, so a handler written now still behaves when another kind is added.

Examples

GPAL Fluent: High-level fluent C# API

//A navigation that never loaded is not always an error. A page behind a challenge, a slow origin, or a url that redirects somewhere unexpected are all things a workflow may want to retry or step past, which is why the decision is handed back rather than made for you.

GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.CallOnFail(OnBrowserFailure)

.GoTo("https://example.com/report");


static CallIfStatus OnBrowserFailure(IBrowser browser, GPALFailure failure, string detail)

{

CallIfStatus retVal = CallIfStatus.Handled;


if (GPALFailure.Navigation == failure)

{

GPAL.PublishSimpleEvent(GPALEventType.CAUTION, $"Retrying after [{detail}]");

_ = browser.Refresh;

}

else

retVal = CallIfStatus.Terminate;


return retVal;

}

💬 Ask GPAL