Skip to content

Latest commit

 

History

History
128 lines (94 loc) · 14.3 KB

nativescript.md

File metadata and controls

128 lines (94 loc) · 14.3 KB
title NativeScript
description Send live components, signals, injectors, stores, change detection, leaks and errors from a NativeScript Angular app on a simulator or device to the devtools on your machine.
Inspect a NativeScript Angular app running on a simulator, an emulator or a phone. The app reports to a devtools server on your machine over a WebSocket.

NativeScript

A NativeScript Angular app renders into @nativescript/core views, so it has no DOM for the browser overlay to walk. The @pangular-inspector/devtools/overlay-nativescript entry point walks the NativeScript view tree instead and sends live data to a devtools server that runs on your machine.

This page describes what the overlay shows and how it works. To add it to an app, follow Set up NativeScript.

What it shows

Tab On NativeScript
Components The component tree, paths and the detail panel. Pointing at a component in the panel outlines it on the device. Change detection records cycles with their causes and OnPush hints, and Leaks lists effects and subscriptions, with navigations counted from the app's Router.
Signals The signal graph of the selected component, with its write history.
Injectors Element injectors and environment injectors with their providers. Show value reads a created provider's value, and Startup shows the Angular version and when the app was first stable.
Store Live @ngrx/signals and @ngrx/store state, the change log, sessions and restore, and NGXS stores. The store list names the app NativeScript (iOS) or NativeScript (Android).
Queries The TanStack Query clients the app injected, with their queries and mutations.
Pipes The pipes in use, with their instances and the components that use them.
Errors Errors from Angular's ErrorHandler and the Application uncaughtError and discardedError events, the console, and the NG0100 and missing provider explainers.
Audit The findings of change detection, leaks and errors, and before and after sessions. axe has no DOM to check.
Plugins The views of page plugins the app registers.

The source scans (routes, pipes, NgRx declarations) come from the server, so they work as with the Standalone CLI. There is no in-app popup.

The server's configuration applies to the app: inspectors you turn off there are not collected, and redaction.secretNames masks values before they leave the device.

What needs a browser

These features read or draw the DOM, or run in the browser, so a NativeScript app has none of them. The panel hides the picker and the live views for the app, Run axe says the app has no DOM, and the agent tools answer the same instead of asking another tab.

Feature Why it is missing
Pick component on page Picking listens for a click on a DOM element.
Flash checks, Performance track and Angular profiling They draw over DOM elements or into the browser's Performance panel.
Checks that changed nothing The recording counts them by watching DOM updates.
Destroyed and retained instances in Leaks A development build keeps every destroyed instance in Angular's DI debug data, so only a detached view would show a leak, and telling one apart asks Angular about a DOM element.
Provider construction times in Startup They need the startup hook, which loads before *Angular in a browser.
axe, screenshot-component, hydration and the console handles They read or copy the DOM.
Router, Forms and SSR & HTTP tabs The NativeScript overlay does not collect them.

Hovering a row still outlines the component on the device.

Where it shows in the panel

The live data shows in the same tabs as a browser page.

Server Where the app shows
Standalone CLI The panel at http://localhost:9999/, without ?view.
A hub (Express or the Vite plugin) The Angular dock in the side rail.

The NativeScript dock (?view=nativescript) shows no live data. It is a setup card, Inspect NativeScript apps, with the setup steps and a link to the setup guide.

The overlay marks its component reports with platform: 'nativescript', the URL / and the title NativeScript (iOS) or NativeScript (Android). list-pages lists the app with the NativeScript platform. See Agent tools.

Requirements

  • A development build. Angular publishes its debug API on globalThis.ng only when ngDevMode is on. Start the overlay inside an if (__DEV__) check.
  • @nativescript/core, an optional peer dependency of the package. The overlay reads the root view and the platform from it.
  • A WebSocket global. The NativeScript runtime has none, so import @valor/nativescript-websockets first in src/polyfills.ts. Without it, the overlay logs a warning that names the package and does not start.
  • initNativeScriptOverlay() called before runNativeScriptAngularApp(), so the injector inspector gets its provider lists. See How it works.
  • A server started with --no-auth, since the app cannot enter the one-time code the panel asks for. Against a server with auth on, the overlay logs a warning that says to start it with --no-auth, and tries again every retryMs.

Set up

Set up NativeScript walks through it: install the packages, add the WebSocket global, start the overlay and run the server. It also covers where the overlay connects from a simulator, an emulator or a device, and how to run the demo in examples/nativescript.

Options

initNativeScriptOverlay() takes an optional object:

Option Default What it does
baseURL defaultDevtoolsBaseURL() Absolute URL of the devtools server.
intervalMs The server's limits.refreshMs How often the app reports, in milliseconds.
retryMs 5000 How long to wait before connecting again after a failure or a dropped socket.

defaultDevtoolsBaseURL(port = 9999) is exported from the same entry point and picks the address by platform:

Platform Default baseURL
iOS http://localhost:9999/
Android http://10.0.2.2:9999/

10.0.2.2 is how the Android emulator reaches its host. A physical device needs your machine's LAN address as baseURL.

initNativeScriptOverlay() returns a function that stops the overlay and tells the server to forget every report the app sent.

How it works

  • Host tree: the overlay walks the @nativescript/core views under the app's root view with the same collectors as the browser overlay. It starts at the host of the root component, found through *Angular's debug API, and looks the root up again on every walk, since NativeScript replaces the root view on some navigations. A host is named by its component's selector.
  • Injector profiler: *Angular wires the profiler that backs the provider lists only when a window global exists as the platform is created. The overlay defines window until *Angular publishes ng.getComponent, then removes it. If window or ng already exist, it leaves them alone.
  • Web shims: the devframe client reads location and navigator. The overlay defines them from baseURL when the runtime has none, and leaves them in place.
  • Transport: the overlay connects over a WebSocket only, since the NativeScript fetch has no streaming body.
  • Store stand-in: initNativeScriptOverlay() puts the Redux DevTools stand-in in place before the app starts, so NGXS stores report without the store-hook entry. A store library that looks for the extension on window finds nothing there, since a NativeScript app has no window once it started. When the server turns the ngrx inspector off, the overlay removes it again.
  • Angular version: change detection recording and Startup read the version from the ng-version value *Angular sets on the root view. When the renderer keeps none, recording stays off and the Change detection section says the page has no profiler, as in a browser, since taking Angular's profiler without knowing the version could evict another one for good.
  • Reporting: the app collects every intervalMs and sends a report when it changed. The Leaks scan walks the views again when the component tree changed, and at least every 30 seconds. When a report has not changed for a while, the app asks the server whether it still holds it, and sends it again only if not. When the connection fails or drops, it logs one warning and tries again every retryMs. The app keeps one page id for as long as the overlay runs, so a reconnect does not show it as a new page.
  • Highlight: when the panel or the highlight agent tool points at a component, the overlay sets a 2 px #68b6ff border on the first view under the host that draws something. It restores the previous border when the pointer leaves the row, after the duration the highlight tool asks for, or after two seconds.

FAQ

Check the app log for a [pangular] line. A warning about a missing WebSocket global means @valor/nativescript-websockets is not imported first in src/polyfills.ts. A warning about reaching the server means the address is wrong for where the app runs; see where the overlay connects. A release build has no ng global, so nothing is collected there. The overlay has to start before runNativeScriptAngularApp() creates the platform. Call initNativeScriptOverlay() above it in src/main.ts. The dock is a setup card. The app's data shows in the Angular dock, or in the panel without ?view on the standalone CLI.

Where to next