This is the error I'm getting:
Response Body: {"value":{"error":"unknown error","message":"unknown error: unhandled inspector error: {\"code\":-32000,\"message\":\"No resource with given identifier found\"}
Here is my code:
class TestClassCDP:
#Workaround for driver.execute_cdp_cmd('Performance.enable', {}) which doesn't work with remote drivers.
async def send(self, driver, cmd, params={}):
resource = "/session/%s/chromium/send_command_and_get_result" % driver.session_id
url = driver.command_executor._url + resource
body = json.dumps({'cmd': cmd, 'params': params})
response = driver.command_executor._request('POST', url, body)
return response.get('value')
async def start_listening(self, driver, connection, session, devtools, listener):
try:
async for event in listener:
logging_info(f"Event: {event}", 'chrome', 'test_name', 'myEnv')
request_id = str(event.request_id)
print(event)
logging_info(f"Event Request ID: {request_id}", 'chrome', 'test_name', 'myEnv')
logging_info(f"-------------------------------------------------END EVENT-------------------------------------------------", 'chrome', 'test_name', 'myEnv')
param = {
'requestId': request_id
}
response_body = await self.send(driver, 'Network.getResponseBody', param)
logging_info(f"Response Body: {response_body}", 'chrome', 'test_name', 'myEnv')
logging_info(f"Tried getting the body for this request ID: {request_id}", 'chrome', 'test_name', 'myEnv')
@pytest.mark.trio
async def test_intercept(self, results_folder_path, myBrowser, myEnv, myUserRole):
test_name = f'test_intercept{get_date_time()}'
fails_file_path = results_folder_path + '/fails.txt'
#Make a folder to hold screenshots
screenshots_folder_path = make_screenshots_folder(results_folder_path, myBrowser, test_name, myUserRole)
driver = webdriver.Chrome()
async with driver.bidi_connection() as connection:
session, devtools = connection.session, connection.devtools
driver.get('https://www.google.com')
await session.execute(devtools.network.enable())
listener = session.listen(devtools.network.ResponseReceived)
async with trio.open_nursery() as nursery:
nursery.start_soon(self.start_listening, driver, connection, session, devtools, listener) # start_listening blocks, so we run it in another coroutine
driver.get('https://www.bing.com')
Here is an example of the logs this code generates:
2023-12-01 09:28:29,471 root INFO --MESSAGE: Event Request ID: 672.57 --TEST NAME: test_name --BROWSER: chrome --ENVIRONMENT: myEnv
2023-12-01 09:28:29,471 root INFO --MESSAGE: -------------------------------------------------END EVENT------------------------------------------------- --TEST NAME: test_name --BROWSER: chrome --ENVIRONMENT: myEnv
2023-12-01 09:28:29,506 root INFO --MESSAGE: Response Body: {"value":{"error":"unknown error","message":"unknown error: unhandled inspector error: {\"code\":-32000,\"message\":\"No resource with given identifier found\"}\n (Session info: chrome=118.0.5993.70)","stacktrace":"\tGetHandleVerifier [0x00007FF6C4818EF2+54786]\n\t(No symbol) [0x00007FF6C4785612]\n\t(No symbol) [0x00007FF6C463A64B]\n\t(No symbol) [0x00007FF6C46293D8]\n\t(No symbol) [0x00007FF6C46274DD]\n\t(No symbol) [0x00007FF6C4627E6E]\n\t(No symbol) [0x00007FF6C4627DA0]\n\t(No symbol) [0x00007FF6C463CFC3]\n\t(No symbol) [0x00007FF6C46C11FA]\n\t(No symbol) [0x00007FF6C469BE6A]\n\t(No symbol) [0x00007FF6C46B4D02]\n\t(No symbol) [0x00007FF6C469BC43]\n\t(No symbol) [0x00007FF6C4670941]\n\t(No symbol) [0x00007FF6C4671B84]\n\tGetHandleVerifier [0x00007FF6C4B67F52+3524194]\n\tGetHandleVerifier [0x00007FF6C4BBD800+3874576]\n\tGetHandleVerifier [0x00007FF6C4BB5D7F+3843215]\n\tGetHandleVerifier [0x00007FF6C48B5086+694166]\n\t(No symbol) [0x00007FF6C4790A88]\n\t(No symbol) [0x00007FF6C478CA94]\n\t(No symbol) [0x00007FF6C478CBC2]\n\t(No symbol) [0x00007FF6C477CC83]\n\t(No symbol) [0x00007FFFAB257344]\n\tRtlUserThreadStart [0x00007FFFACA426B1+33]\n"}} --TEST NAME: test_name --BROWSER: chrome --ENVIRONMENT: myEnv
2023-12-01 09:28:29,506 root INFO --MESSAGE: Tried getting the body for this request ID: 672.57 --TEST NAME: test_name --BROWSER: chrome --ENVIRONMENT: myEnv
Given the logs, I am supplying Network.getResponseBody with the event request ID that was just caught by the listener for the event "ResponseReceived". Although I give it the correct ID and immediately try to get the body, I'm getting an error. Could anyone tell me what I'm doing wrong here?