ulixee / hero

The web browser built for scraping
MIT License
805 stars 41 forks source link

feat(core): flow handlers #79

Closed blakebyrnes closed 2 years ago

blakebyrnes commented 2 years ago

This PR introduces Flow Handlers.

Flow handlers allow you to register blocks of code to run when "states" are triggered. "States" are automatically checked if an error occurs in an execJsPath, or an interact command. You can also manually trigger checking states with checkFlowHandlers.

When FlowHandlers are checked, the state is checked for all of them at once, and the first one to match will be run. Commands are re-tried after a single flow handler is matched. If they error again, we will retry the flow handlers up to 3 times to correct the state. Any errors occurring in flow handler will bubble up to the current command (otherwise it becomes very difficult to track errors originating in the FlowHandlers).

You can use this feature to:

Flow Handlers are "implicitly" attached to the active tab. We might need to enhance this feature at some future date to better handle multiple open tabs concurrently, but it didn't feel like a priority for this version.

Some changes to the client library are attached to this change:

To help track the active FlowHandlers that change state, the CommandsTable is modified, and a FlowHandlers table is introduced.