Lack of support of some CDP API methods for debugging
- Dominant language
- JavaScript
- Stars
- 11.3k
- Forks
- 859
- Avg merge
- 1h 30m
- Merged PRs (30d)
- 3
Description
Hello, we are [React Native Tools](https://github.com/microsoft/vscode-react-native) team. Now are migrating our extension on use of [js-debug's](https://github.com/microsoft/vscode-js-debug) debugger. We faced several issues when we were trying to debug a Hermes app by means of `js-debug`.
## 1. Hermes engine doesn't support flat session API
`js-debug` is flat session API oriented extension. Flat sessions API allows to create a single connection for several debug sessions. So it isn't required to create a separate session for each debugged process.
Here is the list of methods from `Target` domain that support flat sessions:
- [Target.attachToTarget](https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-attachToTarget)
- [Target.sendMessageToTarget](https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-sendMessageToTarget)
- [Target.setAutoAttach](https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-setAutoAttach)
- [Target.attachToBrowserTarget](https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-attachToBrowserTarget)
Under the hood `js-debug` uses [Target.attachToBrowserTarget](https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-attachToBrowserTarget) method to get debugged page.
We tried to debug (using `js-debug` extension) a Hermes app as an application launched in Chrome, but that was unsuccessful attempt. We found out the reason is that a Hermes app doesn't return any target on `Target.attachToBrowserTarget` request, it returns just an empty response and this is the main problem.
`js-debug` sends such message:
```
{"id":1,"method":"Target.attachToBrowserTarget","params":{}}
```
And a Hermes app replies the following:
```
{"result":{},"id":1}
```
So it seems that Hermes engine hasn't supported flat sessions API yet.
According to [Google documentation](https://bugs.chromium.org/p/chromium/issues/detail?id=991325) flat sessions API is going to be the default API and [Target.attachToTarget](https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-attachToTarget) (which is currently used) method will be deprecated.
## 2. Hermes engine doesn't return objects correctly in `Runtime.evaluate` method
After unsuccessful attempts to debug a Hermes app using Chrome scenarios, we tried to attach to it as a Node process(without flat session API support). In this case there are also some problems. `js-debug` uses `Runtime.evaluate` method and it expects a Hermes app to return some specific objects, but Hermes engine returns something like this:
```
{
"result": {
"result": {
"objectId": "1",
"description": "Object",
"className": "Object",
"type": "object"
}
},
"id": 6
}
```
We found out that `Runtime.evaluate` method can only return values of simple types, e.g. `number`, but if we want to return some object (e.g. `{test: 4}`), Hermes will send us a reply similar to the one above.
## 3. Hermes engine doesn't supported several CDP methods used by `js-debug`
Hermes engine sends just empty responses on the following requests:
- Debugger.setPauseOnExceptions
- Debugger.setInstrumentationBreakpoint
- Runtime.runIfWaitingForDebugger
- Debugger.setAsyncCallStackDepth
All method, besides `Debugger.setPauseOnExceptions` are absent in [Hermes inspector message types list](https://github.com/facebook/react-native/blob/master/ReactCommon/hermes/inspector/tools/message_types.txt).
We attach [logs](https://github.com/facebook/hermes/files/4455498/log.txt) of CDP communication.
Is it possible to implement missing API methods?
`Runtime.evaluate` method's correct work is crucial for the debugger, so could you please take a look on it?
Contributor guide
Assessment
This issue has not been assessed yet.