Skip to main content
@capgo/capacitor-keep-awake Device APIs Open source

Keep Awake Capacitor plugin

Prevent device screen from dimming or sleeping for video players, navigation, and presentations

Install

bun add @capgo/capacitor-keep-awake bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-keep-awake
  • pnpm add @capgo/capacitor-keep-awake
  • yarn add @capgo/capacitor-keep-awake

Guide

How to use Keep Awake in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

Keep Awake plugin preview QR code

Using @capgo/capacitor-keep-awake

Capacitor Keep Awake Plugin for preventing the device screen from dimming/sleeping.

Install

bun add @capgo/capacitor-keep-awake
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { KeepAwake } from '@capgo/capacitor-keep-awake';

API at a glance

Method Description
keepAwake Prevent the device from dimming the screen.
allowSleep Allow the device to dim the screen (disable keep awake).
isSupported Check if the keep awake feature is supported on the current platform.
isKeptAwake Check if the device is currently being kept awake.

Examples

keepAwake()

Prevent the device from dimming the screen.

import { KeepAwake } from '@capgo/capacitor-keep-awake';

await KeepAwake.keepAwake();
console.log('Screen will stay awake');

allowSleep()

Allow the device to dim the screen (disable keep awake).

import { KeepAwake } from '@capgo/capacitor-keep-awake';

await KeepAwake.allowSleep();
console.log('Screen can now dim');

isSupported()

Check if the keep awake feature is supported on the current platform.

import { KeepAwake } from '@capgo/capacitor-keep-awake';

const { isSupported } = await KeepAwake.isSupported();
if (isSupported) {
  console.log('Keep awake is supported');
}

isKeptAwake()

Check if the device is currently being kept awake.

import { KeepAwake } from '@capgo/capacitor-keep-awake';

const { isKeptAwake } = await KeepAwake.isKeptAwake();
console.log('Is kept awake:', isKeptAwake);

Full reference

Keep going from Using @capgo/capacitor-keep-awake

If you are using Using @capgo/capacitor-keep-awake to plan native media and interface behavior, connect it with @capgo/capacitor-keep-awake for the implementation detail in @capgo/capacitor-keep-awake, Getting Started for the implementation detail in Getting Started, Using @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-live-activities, and Using @capgo/capacitor-video-player for the native capability in Using @capgo/capacitor-video-player.

FAQ

Keep Awake plugin FAQ

How do I install the Keep Awake plugin in a Capacitor app?

Run "bun add @capgo/capacitor-keep-awake" (or "npm install @capgo/capacitor-keep-awake"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-keep-awake" in your app code.

Does @capgo/capacitor-keep-awake work with React, Vue and Angular?

Yes. Keep Awake is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-keep-awake support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-keep-awake free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-keep-awake/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Keep Awake without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Keep Awake changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo