NativeScript / android

NativeScript for Android using v8
https://docs.nativescript.org/guide/android-marshalling
Apache License 2.0
527 stars 135 forks source link

In line debugger - can't connect through websocket #1640

Closed dev4s closed 4 years ago

dev4s commented 4 years ago

Environment

"dependencies": {
    "@nativescript/core": "^7.0.8",
    "@nativescript/webpack": "^3.0.0",
    "nativescript-couchbase-plugin": "^0.9.6",
    "nativescript-fonticon": "^2.0.2",
    "nativescript-vue": "^2.6.1",
    "nativescript-vue-navigator": "^1.2.0",
    "vue-class-component": "^7.2.6",
    "vue-property-decorator": "^9.0.0"
},
"devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@nativescript/android": "7.0.0",
    "@nativescript/types": "^7.0.0",
    "@types/node": "^13.13.21",
    "babel-loader": "^8.1.0",
    "nativescript-vue-template-compiler": "^2.6.0",
    "node-sass": "^4.13.1",
    "typescript": "^3.8.3",
    "vue": "^2.6.11",
    "vue-loader": "^15.9.1"
}

Describe the bug The system doesn't break on the 'debugger'' line when set on main.ts. and shows the message: 'can't connect through WebSocket'.

To Reproduce

  1. create a simple Vue project with TS.
  2. add a debugger to main.ts.
  3. run debugging from the command line (the specified one I've used:
    ns debug android --debug-brk --emulator --timeout 300
  4. go to the predefined URL created by the ns command line (devtools://devtools/bundled/inspector.html?ws=localhost:40000).
  5. you should get the WebSocket disconnected message from chrome devtools.

Expected behavior

  1. Chrome devtools should break on the breakpoint.

Sample project

import Vue from 'nativescript-vue';
import Main from './components/main.vue';

debugger;

Vue.config.silent = false;

new Vue({
    render: (h) => h('frame', [h(Main)]),
}).$start();

Additional context I've set on the main.ts the breakpoint by using the 'debugger' (Debug CLI) option. After that I've run the command specified for debugging, I couldn't connect (at least that was what chrome devtools was showing). Some couple of tries later I've said enough and started to debug the android runtime by using one of your guidelines regarding debugging starting scripts in android-runtime (Debug android runtime), found the problem with the ShouldBreak method (it couldn't handle the scope with the isolate_) and also with getDocument method (The document is empty as it isn't loaded yet, I think) . To be honest, I'm not a specialist regarding C++ and Java, I'm experienced mostly in C# and some of the JavaScript.

NathanaelA commented 4 years ago

Thank you very much!!!

I have tested this PR with several apps; and it does appear to restore debugging ability with the --debug-brk command. Technically the --debug-brk command SHOULD be breaking on the very first line of JS code; but this does fix the issue with it crashing out. So this is a awesome step in fixing the whole issue. We will have to figure out why the --debug-brk command isn't breaking on the first line of code still, but that can be a separate PR. Fixing Crashes is a good thing. :grinning: