ChromeDevTools / devtools-protocol

Chrome DevTools Protocol
https://chromedevtools.github.io/devtools-protocol/
BSD 3-Clause "New" or "Revised" License
1.15k stars 226 forks source link

When using flat protocol, messages are routed to the target via the sessionId attribute. #160

Closed leksito closed 5 years ago

leksito commented 5 years ago

http://localhost:9222/json/list

[
    {
        "description": "",
        "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/90C1A35F08B6317C052A3A4429491B63",
        "id": "90C1A35F08B6317C052A3A4429491B63",
        "title": "about:blank",
        "type": "page",
        "url": "about:blank",
        "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/90C1A35F08B6317C052A3A4429491B63"
    }
]

I'm use Target.attachToBrowserTarget to get sessionId: {'id': 1001, 'result': {'sessionId': '81DD0C3461871103A0467DD8D0393E2C'}}

then I use Target.sendMessageToTarget to navigate using Page.navigate:

{
    "id": 1002,
    "method": "Target.sendMessageToTarget",
    "params": {
        "message": "{\"id\": 1502, \"method\": \"Page.navigate\", \"params\": {\"url\": \"http://www.google.com\"}}",
        "sessionId": "81DD0C3461871103A0467DD8D0393E2C"
    }
}

and get the error "When using flat protocol, messages are routed to the target via the sessionId attribute.".

What is mean flat sessionId mode? Why I got this error if sessionId is defined?

roblourens commented 5 years ago

I think you are supposed to call Page.navigate directly with the sessionid

aslushnikov commented 5 years ago

@leksito Pease check out the https://github.com/aslushnikov/getting-started-with-cdp/ on how to use Flatten protocol.

leksito commented 5 years ago

@aslushnikov but when i use as in your article, i get another error: {u'sessionId': u'ECC037FD6FBE59522113CABDA0A9ABC0', u'id': 2, u'error': {u'message': u"'Page.enable' wasn't found", u'code': -32601}}

Another example. Message that i send via ws: {'sessionId': u'B7AF31201C0E716F891BC294689E936D', 'params': {'url': 'https://www.google.com'}, 'id': 2, 'method': 'Page.navigate'} Error: {'sessionId': u'B7AF31201C0E716F891BC294689E936D', 'params': {'url': 'https://www.google.com'}, 'id': 2, 'method': 'Page.navigate'}

But when i use 'attachToTarget' method it works.