@capgo/capacitor-network-diagnostics

June 16, 2026 · View on GitHub

Capgo - Instant updates for Capacitor

➡️ Get Instant updates for your App with Capgo

Missing a feature? We’ll build the plugin for you 💪

Capacitor plugin for native network diagnostics. It checks connection type, native HTTP reachability, TCP ports, WebSocket handshakes, download speed, and application-level packet loss from iOS and Android.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-network-diagnostics` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-network-diagnostics
npx cap sync

What It Tests

  • Current native connection type: WiFi, cellular, ethernet, VPN, none, or unknown.
  • OS network flags: validated internet on Android, captive portal on Android, expensive or constrained path where available.
  • Native HTTP/HTTPS URL reachability with status code and latency.
  • Native TCP host:port connectivity.
  • Native WebSocket handshake for ws:// and wss://.
  • Download throughput against your own test file endpoint.
  • Packet loss using repeated TCP connects or HTTP requests.

Raw ICMP ping is not consistently available to App Store and Play Store apps. testPacketLoss therefore measures application-level loss with TCP or HTTP probes.

Usage

import { NetworkDiagnostics } from '@capgo/capacitor-network-diagnostics';

const status = await NetworkDiagnostics.getNetworkStatus();

const api = await NetworkDiagnostics.testUrl({
  url: 'https://api.example.com/health',
  method: 'HEAD',
  timeoutMs: 5000,
});

const port = await NetworkDiagnostics.testPort({
  host: 'api.example.com',
  port: 443,
  timeoutMs: 3000,
});

const ws = await NetworkDiagnostics.testWebSocket({
  url: 'wss://ws.example.com/socket',
  timeoutMs: 5000,
});

const packetLoss = await NetworkDiagnostics.testPacketLoss({
  mode: 'tcp',
  host: 'api.example.com',
  port: 443,
  count: 10,
});

console.log({ status, api, port, ws, packetLoss });

Combined Diagnostic Run

const report = await NetworkDiagnostics.runDiagnostics({
  urls: [{ url: 'https://api.example.com/health' }],
  ports: [{ host: 'api.example.com', port: 443 }],
  websockets: [{ url: 'wss://ws.example.com/socket' }],
  download: {
    url: 'https://speed.example.com/5mb.bin',
    maxBytes: 5 * 1024 * 1024,
  },
  packetLoss: {
    mode: 'tcp',
    host: 'api.example.com',
    port: 443,
    count: 10,
  },
});

console.log(report.issues);

Platform Notes

  • iOS: no extra permissions are required. Connection type comes from Network.framework.
  • Android: the plugin declares android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE.
  • Web: provided as a development fallback. Browsers cannot open raw TCP sockets, and URL checks are limited by CORS.

API

Native network diagnostics API.

getNetworkStatus()

getNetworkStatus() => Promise<NetworkStatusResult>

Read the current native connection type and platform network flags.

Returns: Promise<NetworkStatusResult>


testUrl(...)

testUrl(options: UrlTestOptions) => Promise<UrlTestResult>

Test whether an HTTP or HTTPS URL can be reached from native networking.

ParamType
optionsUrlTestOptions

Returns: Promise<UrlTestResult>


testPort(...)

testPort(options: PortTestOptions) => Promise<PortTestResult>

Test whether a TCP host:port can be opened from native networking.

ParamType
optionsPortTestOptions

Returns: Promise<PortTestResult>


testWebSocket(...)

testWebSocket(options: WebSocketTestOptions) => Promise<WebSocketTestResult>

Test whether a WebSocket URL can complete its native handshake.

ParamType
optionsWebSocketTestOptions

Returns: Promise<WebSocketTestResult>


testDownloadSpeed(...)

testDownloadSpeed(options: DownloadSpeedTestOptions) => Promise<DownloadSpeedTestResult>

Measure download throughput from a native HTTP request.

ParamType
optionsDownloadSpeedTestOptions

Returns: Promise<DownloadSpeedTestResult>


testPacketLoss(...)

testPacketLoss(options: PacketLossTestOptions) => Promise<PacketLossTestResult>

Estimate application-level packet loss with repeated TCP or HTTP probes.

ParamType
optionsPacketLossTestOptions

Returns: Promise<PacketLossTestResult>


runDiagnostics(...)

runDiagnostics(options?: RunDiagnosticsOptions | undefined) => Promise<RunDiagnosticsResult>

Run several diagnostics and return a compact issue list.

ParamType
optionsRunDiagnosticsOptions

Returns: Promise<RunDiagnosticsResult>


getPluginVersion()

getPluginVersion() => Promise<PluginVersionResult>

Returns the platform implementation version marker.

Returns: Promise<PluginVersionResult>


Interfaces

NetworkStatusResult

Current native network state.

PropTypeDescription
connectedbooleanTrue when the platform reports an active network path.
connectionTypeConnectionTypeBest-effort active transport type.
internetReachablebooleanTrue when the OS marks the network as internet-capable or validated.
expensivebooleanTrue for metered or expensive network paths.
constrainedbooleanTrue when the OS reports a low-data or constrained network path.
captivePortalbooleanTrue when Android reports captive portal capability.
detailsRecord<string, string | number | boolean>Native platform details useful for debugging.

UrlTestResult

Native HTTP URL reachability result.

PropType
urlstring
methodUrlTestMethod
okboolean
reachableboolean
durationMsnumber
statusCodenumber
finalUrlstring
errorCodestring
errorMessagestring

UrlTestOptions

Options for native HTTP URL reachability checks.

PropTypeDescription
urlstringHTTP or HTTPS URL to test.
methodUrlTestMethodHTTP method. Defaults to HEAD.
timeoutMsnumberRequest timeout in milliseconds. Defaults to 10000.
followRedirectsbooleanFollow redirects. Defaults to true.

PortTestResult

Native TCP port check result.

PropType
hoststring
portnumber
openboolean
durationMsnumber
errorCodestring
errorMessagestring

PortTestOptions

Options for native TCP port checks.

PropTypeDescription
hoststringHostname or IP address.
portnumberTCP port to open.
timeoutMsnumberSocket timeout in milliseconds. Defaults to 5000.

WebSocketTestResult

Native WebSocket handshake result.

PropType
urlstring
openboolean
durationMsnumber
protocolstring
statusCodenumber
errorCodestring
errorMessagestring

WebSocketTestOptions

Options for native WebSocket handshake checks.

PropTypeDescription
urlstringws:// or wss:// URL to test.
timeoutMsnumberHandshake timeout in milliseconds. Defaults to 10000.

DownloadSpeedTestResult

Native download speed measurement result.

PropType
urlstring
okboolean
durationMsnumber
bytesDownloadednumber
bytesPerSecondnumber
mbpsnumber
statusCodenumber
errorCodestring
errorMessagestring

DownloadSpeedTestOptions

Options for native download speed measurement.

PropTypeDescription
urlstringHTTP or HTTPS URL returning a downloadable body.
maxBytesnumberMaximum bytes to read before stopping. Defaults to 5242880 (5 MiB).
timeoutMsnumberRequest timeout in milliseconds. Defaults to 30000.

PacketLossTestResult

Application-level packet loss result.

PropType
modePacketLossMode
targetstring
sentnumber
receivednumber
lostnumber
lossPercentnumber
averageLatencyMsnumber
minLatencyMsnumber
maxLatencyMsnumber
errorCodestring
errorMessagestring

PacketLossTestOptions

Options for packet loss measurement.

Native apps cannot rely on raw ICMP ping on both iOS and Android, so this method measures application-level loss with repeated TCP connects or HTTP requests.

PropTypeDescription
modePacketLossModeProbe mode. Defaults to tcp when host/port is provided, otherwise http.
hoststringHostname or IP address for TCP probes.
portnumberTCP port for TCP probes.
urlstringHTTP or HTTPS URL for HTTP probes.
countnumberNumber of probes to send. Defaults to 10.
timeoutMsnumberPer-probe timeout in milliseconds. Defaults to 3000.
intervalMsnumberDelay between probes in milliseconds. Defaults to 250.

RunDiagnosticsResult

Combined native network diagnostic result.

PropType
statusNetworkStatusResult
urlsUrlTestResult[]
portsPortTestResult[]
websocketsWebSocketTestResult[]
issuesstring[]
downloadDownloadSpeedTestResult
packetLossPacketLossTestResult

RunDiagnosticsOptions

Options for a combined native network diagnostic run.

PropType
urlsUrlTestOptions[]
portsPortTestOptions[]
websocketsWebSocketTestOptions[]
downloadDownloadSpeedTestOptions
packetLossPacketLossTestOptions

PluginVersionResult

Plugin version payload.

PropTypeDescription
versionstringVersion identifier returned by the platform implementation.

Type Aliases

ConnectionType

'none' | 'wifi' | 'cellular' | 'ethernet' | 'vpn' | 'other' | 'unknown'

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }

UrlTestMethod

'HEAD' | 'GET'

PacketLossMode

'tcp' | 'http'