Skip to main content

cordova-plugin-flashlight Alternative for Capacitor

cordova-plugin-flashlight alternative for Capacitor: torch on/off, toggle, and intensity with @capgo/capacitor-flash for QR and camera companion apps.

Illustration of migrating a Cordova app to Capacitor, used for a flashlight plugin guide

The practical cordova-plugin-flashlight alternative for a Capacitor app is @capgo/capacitor-flash. It maps window.plugins.flashlight callbacks to CapacitorFlash promises with isAvailable, switchOn, switchOff, toggle, and isSwitchedOn, which is the same surface area documented in the Cordova README since version 3.2.0. This guide lists npm facts, install steps, usage, and an API map for your Cordova to Capacitor move.

Why leave cordova-plugin-flashlight in Capacitor

cordova-plugin-flashlight on npm is version 3.2.0. The registry modified timestamp is 14 June 2022. The npm repository URL points to EddyVerbruggen/Flashlight-PhoneGap-Plugin.

The README documents window.plugins.flashlight with:

  • available(callback) to learn if the device has a torch
  • switchOn(success, error, { intensity }) with intensity between 0.0 and 1.0 on iOS
  • switchOff(success, error)
  • toggle(success, error, { intensity })
  • isSwitchedOn() returning a boolean (synchronous in Cordova)
  • A note that Android may lock the camera if the torch stays on after exit via the back button

In a Capacitor codebase the Cordova plugin still routes through cordova.exec with success and error callbacks instead of typed errors.

@capgo/capacitor-flash latest on npm is 8.0.54 with a modified date of 13 November 2026. src/definitions.ts documents isAvailable(), switchOn({ intensity }), switchOff(), toggle(), and isSwitchedOn(). Capgo ships fixes on an open source cadence where a human still reviews, tests and merges 50+ pull requests daily.

Install

bun add @capgo/capacitor-flash
bunx cap sync

No extra native permissions are required beyond what the OS attaches to camera torch access. On Android, turn the torch off when the user leaves the screen so another app can use the camera.

Usage example

import { CapacitorFlash } from '@capgo/capacitor-flash';

export async function pulseTorch() {
  const { value: available } = await CapacitorFlash.isAvailable();
  if (!available) {
    throw new Error('Flashlight not available');
  }

  await CapacitorFlash.switchOn({ intensity: 0.5 });
  await new Promise((resolve) => setTimeout(resolve, 3000));
  await CapacitorFlash.switchOff();
}

Migrating from Cordova to Capacitor

// Before (Cordova)
window.plugins.flashlight.available(function (isAvailable) {
  if (!isAvailable) return;
  window.plugins.flashlight.switchOn(
    function () {},
    function () {},
    { intensity: 0.3 },
  );
});
// After (Capacitor)
import { CapacitorFlash } from '@capgo/capacitor-flash';

const { value: available } = await CapacitorFlash.isAvailable();
if (!available) return;
await CapacitorFlash.switchOn({ intensity: 0.3 });
// Before (Cordova back button)
document.addEventListener('backbutton', function () {
  window.plugins.flashlight.switchOff(exitApp, exitApp);
}, false);
// After (Capacitor, use App plugin or router guard)
import { App } from '@capacitor/app';

await App.addListener('backButton', async () => {
  await CapacitorFlash.switchOff();
});

API mapping table

cordova-plugin-flashlight (window.plugins.flashlight) @capgo/capacitor-flash
available(callback) isAvailable() returns { value: boolean }
switchOn(success, error, { intensity }) switchOn({ intensity?: number })
switchOff(success, error) switchOff()
toggle(success, error, { intensity }) toggle() returns { value: boolean }
isSwitchedOn() (sync boolean) isSwitchedOn() returns Promise<{ value: boolean }>
Cordova plugin install bun add @capgo/capacitor-flash plus bunx cap sync
Not in Cordova getPluginVersion()

Torch control ships in the native binary, so plan a store build after you swap plugins. Use Capgo Build for cloud builds, then ship scanner UI with Capgo live updates where the logic stays in JavaScript. For the full platform move, read the Cordova to Capacitor migration guide.

Live updates for Capacitor apps

When a web-layer bug is live, ship the fix through Capgo instead of waiting days for app store approval. Users get the update in the background while native changes stay in the normal review path.

Latest from our Blog

Capgo gives you the best insights you need to create a truly professional mobile app.