I’m trying to interface with a Chrome instance that has --remote-debugging-port=0
using DevTools Protocol and some Python websocket code a bit like this for communicating with it:
async def send(ws, command):
await ws.send(json.dumps(command))
async for message in ws:
response = json.loads(message)
return response
async def send_msg(url, msg):
print(f"sending to url {url} with message {msg}")
async with websockets.connect(url) as ws:
response = await send(ws, msg)
return response
Currently I can successfully navigate it to URLs, kill the instance, open new tabs, etc using their available protocol names (i.e. Browser.close
, Page.navigate
)
However, when trying to control anything under DOM (e.g. DOM.performSearch
), I get the response:
{'id': 2, 'error': {'code': -32000, 'message': 'DOM agent is not enabled'}}
I’ve tried initialising the DOM by sending a packet like this before anything else:
{'id': 0, 'method': 'DOM.enable', 'params': {}}
but despite receiving a packet like this which would seem to suggest it worked:
response = {'id': 0, 'result': {}}
I still receive the same error:
{'id': 0, 'method': 'DOM.enable', 'params': {}}
I’ve even integrated very very long waits in case DOM.enable
is taking a long time to initialise, but that doesn’t seem to solve the problem either.
Any ideas would be appreciated!