In the following sample code the fail_request is not failing the request but simply keeping it as pending. I have similar issues with get_response_body or fulfill_request.
However all requests that are let to continue (using continue_request) are without any issues.
The import for GeneralFunctions is used for a function that returns a driver object with predefined actions. The import for testSetup provides access to generally used variables.
Is there something that I am doing wrong or is this a Selenium issue when using it with Python?
import trio
import time
from Setup.Setup import testSetup
from Setup.General import GeneralFunctions
from selenium.webdriver.common.by import By
generalFunctions = GeneralFunctions()
async def main1():
driver = generalFunctions.newChrome(testSetup.url)
time.sleep(6)
async with driver.bidi_connection() as connection:
session, devtools = connection.session, connection.devtools
await session.execute(devtools.fetch.enable())
listener = session.listen(devtools.fetch.RequestPaused)
async with trio.open_nursery() as nursery:
driver.refresh()
async for event in listener:
if "userData" in str(event.request.url) and event.request.method == "GET":
try:
await session.execute(devtools.fetch.fail_request(event.request_id, '{"error_reason": "aaaa"}'))
except:
print("problem with target request")
else:
try:
await session.execute(devtools.fetch.continue_request(event.request_id))
except:
print("problem with regular request")
async def main2():
await main1()
trio.run(main2)
Figured it out by myself - I was not checking the exception error and the problem was that fetch.fail_request requires the second parameter to be something like that:
await session.execute(devtools.fetch.fail_request(event.request_id, devtools.network.ErrorReason.FAILED))