GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • NativeScript
  • Blog
  • Community
  • Support
  • Open NativeScript GitHub
  • Debugging

This view

  • Original page
  • New address

GeezerVison is showing docs.nativescript.org — Debugging | NativeScript

NativeScript 9.1 Released → V8 14.9, Vite 8 HMR, built for rapid agentic visual iteration
Dig in→
  • Docs
  • Tutorials
  • Preview
  • Snacks
  • Plugins
  • UI Components
  • API Reference
  • Getting Started

    • Introduction
    • Environment Setup
      • Windows
      • macOS
      • Linux
    • Creating a Project
    • Choosing an editor
    • Troubleshooting
  • Development Workflow

    • CLI Basics
    • Running
    • Debugging
    • Publishing
    • Plugins
    • Recommended Plugins
    • Testing
    • Updating
      • To Latest
  • Project Structure

    • App_Resources/
    • src/
      • fonts/
      • app.css•scss
      • main.js•ts
    • nativescript.config.ts
    • package.json
    • references.d.ts
    • tsconfig.json
    • vite.config.mts
    • webpack.config.js
  • Configuration

    • Config Reference
    • Vite Reference
    • Vite Framework Flavors
    • Webpack Reference
  • Fundamental Concepts

    • Accessibility
    • Animations
    • Best Practices
    • Commonly Used APIs
      • @nativescript/core
        • Application
        • ApplicationSettings
        • Color
        • Connectivity
        • Device
        • FileSystem
        • FPS Meter
        • Http
        • ImageCache
        • Observable
        • Screen
        • Trace
        • Utils
        • XmlParser
    • Data Binding
    • Error Handling
    • Gestures
    • Navigation
      • Using Frames and Pages
      • Using Modals
    • Property System
    • Styling
  • Crash Reporting

    • Using Sentry
  • Developing with Vision Pro

    • Developing with visionOS
    • Previewing visionOS from StackBlitz
  • Agentic Coding

    • Leverage AI assistants
    • Using the Docs with AI
  • Advanced Concepts

    • Adding Native Code
      • Adding Java/Kotlin Code
      • Adding ObjectiveC/Swift Code
      • Generating TypeScript types
    • Extending Native Classes
      • Android
      • iOS
    • Create Custom Native Elements
    • Customizing View Elements
    • Shared Element Transitions
    • Multithreading
    • Multi-Window Development
    • Code Sharing
    • Metadata
    • Marshalling
      • iOS Marshalling
      • iOS Runtime Types
      • Android Marshalling
    • Hooks
    • Platform Version Handling
    • Widgets for iOS
Are you an LLM? You can read better optimized documentation at /guide/debugging.md for this page in Markdown format

There are multiple ways to debug issues in your apps, starting with the simplest form using console.logs. For more complex issues, you may need to use an actual debugger, like Chrome DevTools, XCode developer tools and instruments or the Android Studio developer tools.

Console ​

The quickest way to inspect state is to log values to the console. NativeScript supports console methods like log, info, warn, error, trace, dir, time and timeEnd.

The time(label: string) method starts a new timer and is very useful to measure how long something took. To stop the timer, call timeEnd with the same label, and the execution time will be printed to the console.

ts
console.log('General message')
console.info('Informational message')
console.warn('Warning')
console.error('Error')

// also prints a stack trace to the current line
console.trace('Trace message')

// prints all members of someVariable
console.dir(someVariable)

// starts a timer
console.time('myLabel')
await someLongTask()
// ends a timer and prints elapsed time
console.timeEnd('myLabel')

Additional Resources:

  • MDN Console documentation

Debugging with Chrome DevTools ​

To start a Chrome debugging session, run your app in debug mode:

bash
ns debug android|ios

The ns debug command builds and deploys the app on a connected device or emulator, in case you have multiple devices available you will need to pick one from a list, or pass in the --device <id> from ns devices.

Once the app starts, a URL is printed to the console

bash
Setting up debugger proxy...
Press Ctrl + C to terminate, or disconnect.

Opened localhost 41000
To start debugging, open the following URL in Chrome:
devtools://devtools/bundled/inspector.html?ws=localhost:41000

Visit the printed URL (devtools://devtools/bundled/inspector.html?ws=localhost:41000) in Google Chrome to attach to the debugger session.

You can customize the ns debug command using any of the following options:

  • --debug-brk - stops execution at the first JavaScript line until either the debugger frontend connects or a 30 seconds timeout elapses.
  • --start - attaches the debug tools to an already deployed and running app.
  • --emulator - specifies that you want to debug the app in an emulator.
  • --timeout - number of seconds that the NativeScript CLI will wait for the debugger to boot. Default is 90 seconds.
  • --no-watch - changes in your code will not be livesynced.
  • --clean - forces rebuilding the native application.

If you are new to JavaScript debugging, we recommend reading the following resources from Chrome Developers to get familiar with the basics:

  • Debugging JavaScript

Supported Chrome DevTools features ​

DevTools FeatureAndroidiOS
Debugger✅✅
Console✅✅
Resources (source files)✅✅
Network✅✅
Elements (DOM)✅ (view only)✅ (view only)
Elements (Styles)🟠 computed only🟠 computed only
Memory Profiling✅✅
Timeline and CPU Profiling✅✅

Debugging with VS Code ​

VS Code uses the same protocol as the Chrome DevTools, in order to start a debugging session in VS Code you need to install the NativeScript extension for VS Code.

Note

The VS Code extension for NativeScript is currently outdated and may not work. We are planning on revamping the project and bring it up-to-date with all the latest features soon.

Debugging with XCode ​

If you need to debug parts of the native stack instead of the JavaScript part of your app, you can use the XCode debugger as well as all the XCode Instruments to find issues in your app such as memory leaks, hangs, CPU heavy tasks and more.

To start, prepare the iOS app:

bash
ns prepare ios

This compiles your app source, creates the platforms/ios folder (if it doesn't exist yet). You can pass any of the flags you would normally pass to ns run.

Next, open the platforms/ios/<project-name>.xcworkspace in XCode, either through the XCode browse menu, or from the command line:

bash
open platforms/ios/<project-name>.xcworkspace

Select a target device or simulator, and then run the app via the "Play" button. Navigate to the native code in the XCode project, and place breakpoints, when the app hits those it will pause execution and you will be able to step through the native code.

If a crash occurs, the XCode debugger will stop the execution and print a thread dump and a location where the app is crashing. In many cases the stack will point to symbol identifiers like 0x1088f3960 which usually means the source code is not availble for the offending code (could be an external pre-compiled library). If the crash occurs in the NativeScript runtime itself, you can attach the runtime source to be able to see the exact line that is crashing, and also place breakpoints and step throuhg the runtime code with your application. A detailed guide can be found in the NativeScript iOS Runtime Readme.

Since NativeScript utilises a standard XCode project structure, you can do everything you would typically do with a pure iOS application:

  • debug view hiearchy
  • memory dumps/graphs
  • XCode Instruments: leaks, cpu profiling, hangs and more
  • ...and more

Additional Resources:

  • Apple XCode: Debugging iOS apps
  • Apple XCode: Setting breakpoints
  • Attaching the NativeScript runtime to an app

Debugging with Android Studio ​

If you need to debug parts of the native stack instead of the JavaScript part of your app, you can use Android Studio to find issues in your app.

To start, prepare the Android app:

bash
ns prepare android

This compiles your app source, creates the platforms/android folder (if it doesn't exist yet). You can pass any of the flags you would normally pass to ns run.

Next, open the platforms/android folder in Android Studio, through the Android Studio browse menu.

Tip

If you set up the studio command line launcher, you can quickly open the NativeScript project from the command line with

bash
studio platforms/android

Since NativeScript follows a standard gradle/android application structure, you can do everything you would typically do with a pure Android application:

  • debug view hieararchy
  • memory dumps/graphs
  • cpu profiling
  • ...and more

Additional Resources:

  • Android Studio: Layout Inspector
  • Android Studio: view Logcat logs
  • Androud Studio: Debug your app
Previous
←Running
Next
Publishing→
On this page
  1. Console
  2. Debugging with Chrome DevTools
    1. Supported Chrome DevTools features
  3. Debugging with VS Code
  4. Debugging with XCode
  5. Debugging with Android Studio

Contributors

Ombuwebrigor789
Edit this page

Last updated:

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.