feat: terminate BrowserToolkit to allow rerun #2194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
A step to remedy camel-ai/owl#449 thus camel-ai/owl#450.
Playwright driver supports Async and Sync mode. Current BrowserToolkit is running in sync mode not async (see #1886).
NotImplementedErroris being thrown when trying to rerun OWL instance which is an error extensively discussed in microsoft/playwright-python#462, which seem to be caused by asyncio and Playwright sync version conflicts. But I will show you that this issue maynot look as it seems.In my journey to fix "Building Society issue" related to Stop OWL Feature (see camel-ai/owl#450), I discovered that the
NotImplementedErrorissue traces back to BrowserTookit reinstantiation inconstruct_society():While debugging, an Attribute Error exception was thrown when
self.browser.close()was called beforeself.browser.init(). Thus the first commit.Why _terminate() (Commit No.2)?
To demonstrate, Try to paste then run this code in
browser_toolkit.py:The above code should throw an error such as below. To fix the error below, uncomment
# browser1._terminate()in between the instances. Playwright has astop()function as in docs, thus it seems that you shouldstop()playwright before creating a new instance (at least in the sync mode).This is a step to fix the OWL error by drilling down the _terminate() function then calling it on OWL completion, but is still not complete on OWL's Termination edge cases, which I am polishing (see camel-ai/owl#450).
Checklist
Go over all the following points, and put an
xin all the boxes that apply.Fixes #issue-numberin the PR description (required)pyproject.tomlanduv lockIf you are unsure about any of these, don't hesitate to ask. We are here to help!