Target page, context or browser has been closed
When i ran the local playwright cmd, it loads the browser but quits abruptly after loading google.com;
python main.py --query="Go to Google and type 'Hello World' into the search bar" --env="playwright"
Exception:
Traceback (most recent call last):
File "/Users/ace/dev/tools/browser-use/computer-use-preview/main.py", line 84, in <module>
main()
File "/Users/ace/dev/tools/browser-use/computer-use-preview/main.py", line 73, in main
with env as browser_computer:
^^^
File "/Users/ace/dev/tools/browser-use/computer-use-preview/computers/playwright/playwright.py", line 136, in __exit__
self._context.close()
File "/Users/ace/dev/tools/browser-use/computer-use-preview/.venv/lib/python3.12/site-packages/playwright/sync_api/_generated.py", line 13485, in close
return mapping.from_maybe_impl(self._sync(self._impl_obj.close(reason=reason)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ace/dev/tools/browser-use/computer-use-preview/.venv/lib/python3.12/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
return task.result()
^^^^^^^^^^^^^
File "/Users/ace/dev/tools/browser-use/computer-use-preview/.venv/lib/python3.12/site-packages/playwright/_impl/_browser_context.py", line 599, in close
await self._channel.send("close", {"reason": reason})
File "/Users/ace/dev/tools/browser-use/computer-use-preview/.venv/lib/python3.12/site-packages/playwright/_impl/_connection.py", line 61, in send
return await self._connection.wrap_api_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ace/dev/tools/browser-use/computer-use-preview/.venv/lib/python3.12/site-packages/playwright/_impl/_connection.py", line 528, in wrap_api_call
raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.TargetClosedError: BrowserContext.close: Target page, context or browser has been closed
Hello !
This issue could be related and solve your problem: https://github.com/microsoft/playwright/issues/31950#issuecomment-2265467393
Inside the withenvasbrowser_computer block, is there any code that manually closes the context associated with browser_computer? Are there any other logics (such as multi-threading) that close the context Co in advance before the end of the with block?
Hello !
This issue could be related and solve your problem: microsoft/playwright#31950 (comment)
Doesn't solve it; i don't have such env var.
I am also seeing this issue and dont have such env var.