Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed #221

Open
noembryo opened this issue Feb 9, 2024 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@noembryo
Copy link

noembryo commented Feb 9, 2024

Up until a couple of days ago, I was using v.0.5.2 and everything was OK.
The limit for the DeepL to block my IP was ~400.000 characters.
From yesterday on, it seems that this limit went down to ~20.000/30.000 characters..

So, I tried to update deepl-cli thinking that you might have a fix for this, but I encounter another problem.
After installing deepl-cli v.0.6.0, and updated playwright library to the latest version (v.1.41.2), I get this error::
playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed.

Since I don't see anyone mention anything about it, I have to ask for ideas..

Full traceback:

Task exception was never retrieved
future: <Task finished name='Task-2' coro=<Base.start_translating() done, defined at D:\Apps\DEV\PROJECTS\DeepLa\DeepLa.py:588> exception=TargetClosedError('Target page, context or browser has been closed')>
Traceback (most recent call last):
  File "D:\Apps\DEV\PROJECTS\DeepLa\DeepLa.py", line 613, in start_translating
    await asyncio.gather(*translators)
  File "D:\Apps\DEV\PROJECTS\DeepLa\DeepLa.py", line 625, in translator
    trans_text = await self.translate(chunk)
  File "D:\Apps\DEV\PROJECTS\DeepLa\DeepLa.py", line 667, in translate
    return await t.translate_async(text)
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\deepl\deepl.py", line 121, in __translate
    await page.goto(f"{url}#{self.fr_lang}/{self.to_lang}/{script}")
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\async_api\_generated.py", line 9275, in goto
    await self._impl_obj.goto(
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_page.py", line 484, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_frame.py", line 149, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_connection.py", line 63, in send
    return await self._connection.wrap_api_call(
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_connection.py", line 495, in wrap_api_call
    return await cb()
  File "D:\Apps\DEV\PYTHON\Python38Venv\lib\site-packages\playwright\_impl\_connection.py", line 101, in inner_send
    result = next(iter(done)).result()
playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed
@Wotamin
Copy link

Wotamin commented Mar 26, 2024

Nothing much to add, I have the same issue. Ran on local W11 env.

File "c:\Program Files\Python311\Lib\runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Program Files\Python311\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\Saya\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "C:\Users\Saya\Documents\deepl-cli-0.5.2\deepl\test_deepl.py", line 4, in <module>
    deepl.translate("hello") #=> "こんにちわ"
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Saya\Documents\deepl-cli-0.5.2\deepl\deepl.py", line 86, in translate
    return loop.run_until_complete(self.__translate(script))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\Saya\Documents\deepl-cli-0.5.2\deepl\deepl.py", line 122, in __translate
    await page.goto(f"{url}#{self.fr_lang}/{self.to_lang}/{script}")
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\async_api\_generated.py", line 9275, in goto
    await self._impl_obj.goto(
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_page.py", line 484, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_frame.py", line 149, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 63, in send
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 495, in wrap_api_call
    return await cb()
           ^^^^^^^^^^
  File "C:\Users\Saya\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 101, in inner_send
    result = next(iter(done)).result()
             ^^^^^^^^^^^^^^^^^^^^^^^^^
playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed

@Rokandor
Copy link

Rokandor commented Apr 9, 2024

I am also facing this issue
Error:Target page, context or browser has been closed
And it happens randomly as well without more details

@eggplants
Copy link
Owner

Latest test fails only on Windows. I don't have a Wnidows environment, can anyone debug this?
https://github.com/eggplants/deepl-cli/actions/runs/8888722014

@eggplants eggplants added bug Something isn't working help wanted Extra attention is needed labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants