You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The program cannot exit normally when the browser is closed unexpectedly during script execution.
Maybe this issue isn't necessarily a bug, so any suggestions on how to exit the program gracefully when an error occurs?
Code:
session = hrequests.Session()
resp = session.get('https://www.bing.com/')
with resp.render(headless=False, mock_human=True) as page:
time.sleep(15) # Manually close the browser within this time to simulate abnormal browser closing
page.type('//textarea[@name="q"]', 'Hi!')
Outout:
...
with resp.render(headless=False, mock_human=True) as page:
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/hrequests/browser/browser.py", line 157, in __exit__
self.close()
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/hrequests/browser/browser.py", line 621, in close
self.resp.raw = self.page.content()
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/hrequests/browser/engine.py", line 193, in method
result = attr(*args, **kwargs)
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/hrequests/browser/engine.py", line 200, in method
return _engine.execute(task)
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/hrequests/browser/engine.py", line 163, in execute
return self.__handle_future(future)
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/hrequests/browser/engine.py", line 154, in __handle_future
return future.result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 458, in result
return self.__get_result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/hrequests/browser/engine.py", line 197, in task
res = await result
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/playwright/async_api/_generated.py", line 8867, in content
return mapping.from_maybe_impl(await self._impl_obj.content())
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/playwright/_impl/_page.py", line 536, in content
return await self._main_frame.content()
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 416, in content
return await self._channel.send("content")
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 59, in send
return await self._connection.wrap_api_call(
File "/home/hi/.virtualenvs/projectA/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 520, in wrap_api_call
raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.TargetClosedError: Page.content: Target page, context or browser has been closed
... # Thread hangs
Hi,
The program cannot exit normally when the browser is closed unexpectedly during script execution.
Maybe this issue isn't necessarily a bug, so any suggestions on how to exit the program gracefully when an error occurs?
Code:
Outout:
Env:
hrequests[all]==0.9.1
Python 3.10.12
WSL2 (Ubuntu 22.04.4 LTS)
The text was updated successfully, but these errors were encountered: