Skip to content

[Bug]: Future finished exception=TargetClosedError('Target page, context or browser has been closed') #2426

@jmrodri

Description

@jmrodri

Version

1.43.0

Steps to reproduce

Example steps (replace with your own):

  1. Clone my repo at https://github.com//example
  2. pip install -r requirements.txt
  3. python main.py
  4. You should see the error come up
$ python main.py
status_code 200 | url http://httpbin.org/status/200
Future exception was never retrieved
future: <Future finished exception=TargetClosedError('Target page, context or browser has been closed')>
playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed

Expected behavior

I expect NOT to see any error.

Actual behavior

Future exception was never retrieved message being printed.

Additional context

Enabling PYTHONASYNCIODEBUG=1 gives more information:

$ export PYTHONASYNCIODEBUG=1
$ python main.py
status_code 200 | url http://httpbin.org/status/200
Future exception was never retrieved
future: <Future finished exception=TargetClosedError('Target page, context or browser has been closed') created at /home/jesusr/.pyenv/versions/3.11.4/lib/python3.11/asyncio/base_events.py:427>
source_traceback: Object created at (most recent call last):
  File "/home/jesusr/dev/swiftline/pw-future-error/main.py", line 46, in <module>
    asyncio.run(main())
  File "/home/jesusr/.pyenv/versions/3.11.4/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
  File "/home/jesusr/.pyenv/versions/3.11.4/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/home/jesusr/.pyenv/versions/3.11.4/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/home/jesusr/.pyenv/versions/3.11.4/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/home/jesusr/.pyenv/versions/3.11.4/lib/python3.11/asyncio/base_events.py", line 1914, in _run_once
    handle._run()
  File "/home/jesusr/.pyenv/versions/3.11.4/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/jesusr/dev/swiftline/pw-future-error/main.py", line 42, in main
    await fetch("http://httpbin.org/status/200", "ws://localhost:3000/playwright/chromium")
  File "/home/jesusr/dev/swiftline/pw-future-error/main.py", line 37, in fetch
    response = await browser.close()
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/async_api/_generated.py", line 13658, in close
    return mapping.from_maybe_impl(await self._impl_obj.close(reason=reason))
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/_impl/_browser.py", line 184, in close
    await self._connection.stop_async()
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 283, in stop_async
    self._transport.request_stop()
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/_impl/_json_pipe.py", line 39, in request_stop
    self._pipe_channel.send_no_reply("close", {})
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 70, in send_no_reply
    self._connection.wrap_api_call_sync(
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 527, in wrap_api_call_sync
    return cb()
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 71, in <lambda>
    lambda: self._connection._send_message_to_server(
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 322, in _send_message_to_server
    callback = ProtocolCallback(self._loop)
  File "/home/jesusr/.pyenv/versions/pw-future-error/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 187, in __init__
    self.future = loop.create_future()
  File "/home/jesusr/.pyenv/versions/3.11.4/lib/python3.11/asyncio/base_events.py", line 427, in create_future
    return futures.Future(loop=self)
playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed

Environment

- Operating System: [Debian GNU/Linux 12 (bookworm), Arch Linux]
- CPU: [x86_64]
- Browser: [Chromium]
- Python Version: [3.11.4]
- Other info: ghcr.io/browserless/chromium:latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions