Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a Cordova's hook?

I was wondering if is it possible to debug a javascript hook in Cordova?

My hook is triggered before prepare. My command is

cordova prepare ios

I currently use Visual Studio Code and there is a plugin "Cordova tools" to debug an app at runtime. But my need is to debug at build time.

Any recommandation?

PS : what I mean with debug is real debug, that is to say with breakpoints and display of variables, etc..

like image 909
pom421 Avatar asked Dec 09 '25 12:12

pom421


1 Answers

Updated answer 25 Nov 2019

Since node-inspector is deprecated, here is how I would now do this:

  • Open chrome://inspect in Chrome browser
  • Run node --inspect --inspect-brk /path/to/node_modules/cordova/bin/cordova prepare from the root of my Cordova app project which contains the hook scripts I wish to debug
  • In the Chrome tab, press inspect on the target to open Chrome Dev Tools
  • Under Filesystem tab, select Add folder to workspace and select the directory inside my Cordova project containing the hook scripts
  • Add a breakpoint to my hook script
  • Press Play in Chrome Dev Tools to proceed and hit my breakpoint

Original answer 7 Jun 2017 Here's how I debug my hook scripts:

  • Install node inspector: npm install -g node-inspector
  • From the Cordova project root directory, run the Cordova command via node inspector with appropriate options to trigger my hook script, for example:

    node-debug /path/to/node_modules/cordova/bin/cordova prepare

  • When node inspector opens in a Chrome tab, browse Sources to find your hook script

  • Add a breakpoint
  • Press Resume to continue execution to your breakpoint
  • Then you can interactively debug your hook script:

node inspector

like image 164
DaveAlden Avatar answered Dec 12 '25 05:12

DaveAlden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!