BYTESLIP
Knowledge Base // Tutorial 130

Prevent the Screen From Dimming or Turning Off on Android, and Keep a Web Game Awake

Difficulty: Easy ~5 min One UI ¡ Display ¡ Wake Lock API

You’re reading a recipe, following a guide, or watching your score on a game-over screen, and the screen dims and goes dark. On a Galaxy phone or tablet there are four settings that decide this, and websites can also ask to keep the screen on. This guide covers the settings first, then the few lines of code a site like byteslip.org would use to keep the screen awake during a game.

Ways to keep an Android screen from dimming Five tiles: screen timeout, Keep screen on while viewing, power saving, Stay awake while charging, and the Screen Wake Lock API. SCREEN TIMEOUT KEEP ON WHILE VIEWING POWER SAVING STAY AWAKE (CHARGING) WAKE LOCK API
Safety // Read First

Warnings

ImportantA screen that stays on uses more battery. Samsung’s user guide also warns that showing the same still image for a long time may leave ghost-like afterimages, so don’t leave a static page on for hours. Samsung says screen timeout can’t be turned off completely.

Checklist // Before You Start

What You Need

How this was tested: Settings paths come from Samsung support pages, the Galaxy Tab A9+ user guide, Pixel Phone Help and Android Developers. On Nov 19, 2026 we ran the wake lock code from step 6 on a byteslip.org page in headless Chrome 156. The request returned a screen lock. When we released that lock the way the system does and fired visibilitychange, the code took a new one, and allowSleep() released it. Headless Chrome can’t hide a tab the way a phone does, so the automatic release when you switch apps is as MDN documents it, not something we watched on a device.

Walkthrough // Steps 01–06

Timeout → keep on while viewing → power saving → plugged in → videos → websites

Steps 1–5 are settings anyone can change. Step 6 is for people who build websites.

  1. Step 1: Make the screen timeout longer

    Open Settings, tap Display, then Screen timeout, and pick a time. Samsung says Galaxy devices offer 15 seconds to 10 minutes, with 30 seconds as the default, and the timeout can’t be switched off. Pixel phones use Settings > Display (Display & touch on newer versions) > Screen timeout. Pixel also has Adaptive timeout, which can turn the screen off early when you’re not using it.

    The timer only counts time without a touch. While you tap, the screen stays on.

  2. Step 2: Samsung: turn on Keep screen on while viewing

    Galaxy devices can use the front camera to see that you’re looking at the screen and keep it on. Samsung calls it Keep screen on while viewing (older versions: Smart stay). Where it lives depends on your One UI version:

    • Current Samsung help: Settings > Display > Screen timeout > Keep screen on while viewing.
    • Galaxy Tab A9+ user guide (Android 13 edition): Settings > Advanced features > Motions and gestures > Keep screen on while viewing.

    Quickest: tap the search icon in Settings and type “keep screen on”. Samsung notes it may not work well in low light or if your face isn’t clearly visible, and that it may not be available on some devices or software versions.

  3. Step 3: Check power saving and adaptive brightness

    • Power saving may cut screen timeout to 15 seconds, Samsung says. Find it under Settings > Battery and device care > Battery > Power saving (names vary by version).
    • Adaptive brightness: if the screen gets darker and then brighter while you’re using it, that’s brightness following the room light, not the timeout. Turn it off in Settings > Display.
    • A case or dirt over the proximity sensor near the front camera can also make the screen dim or turn off, Samsung says.
  4. Step 4: Plugged in: Stay awake in Developer options

    For long, plugged-in jobs (a recipe on the counter, a tablet as a scoreboard), Android’s Stay awake switch in Developer options keeps the screen on while the device is plugged in. Android Developers: it “sets your screen to stay on while the device is plugged in.” Unplug, and the normal timeout returns.

    Full steps and when to use it: Keep Android Awake While Charging. When you’re done, turn Developer options off.

  5. Step 5: Watching video: go full screen

    Samsung’s screen timeout page says video apps usually keep the screen on, but a video playing inside a browser page without full screen may still let the timeout kick in. Tap the video’s full-screen icon. More ways to go full screen: How to Make a Website Full Screen on Android.

  6. Step 6: Developers: keep the screen on with the Screen Wake Lock API

    Web pages can ask the browser to keep the screen on while they’re visible. This is the code we’d use on a Byteslip game. It isn’t on the live games yet:

    let wakeLock = null;
    
    async function keepScreenOn() {
      if (!('wakeLock' in navigator)) return;   // older browser: the timeout setting applies
      try {
        wakeLock = await navigator.wakeLock.request('screen');
        wakeLock.addEventListener('release', () => {
          // The lock ended (you released it, or the tab was hidden). Update any on-screen indicator.
        });
      } catch (err) {
        console.warn('Wake lock refused:', err.name);   // for example power saving or low battery
      }
    }
    
    async function allowSleep() {
      if (wakeLock) { await wakeLock.release(); wakeLock = null; }
    }
    
    // Android releases the lock when you switch tabs or apps. Take it back when the page returns.
    document.addEventListener('visibilitychange', () => {
      if (wakeLock !== null && document.visibilityState === 'visible') keepScreenOn();
    });

    Then call it when a run starts and release it a little after it ends. The names here are placeholders for your game’s own functions:

    startButton.addEventListener('click', () => { startGame(); keepScreenOn(); });
    
    function onGameOver() {
      showScoreAndLeaderboard();
      setTimeout(allowSleep, 2 * 60 * 1000);   // let the screen sleep two minutes after a run ends
    }
    • Why a game needs it: in Mr. Snakey you tap the D-pad all the time, and every tap counts as activity. The screen goes dark in the quiet moments: a pause, or the game-over screen while you read your score and the global leaderboard.
    • MDN says a request can be refused, for example by power saving or a low battery, and the lock is released when the page is hidden. That’s why the code catches errors and listens for visibilitychange.
    • Release it when you no longer need it, and consider a visible on/off control so people know.
Pro Tip

Match the method to the moment

Questions // FAQ

FAQ

Can I turn screen timeout off completely?

Not on Galaxy devices, Samsung says; 10 minutes is the longest choice. For longer, use Stay awake while plugged in.

Does Keep screen on while viewing record me?

Samsung describes it as using the front camera to detect your face so the screen stays on. If you’d rather not use the camera, use a longer timeout instead.

Can a website keep my screen on without asking?

Browsers may allow it without a prompt, but only while the page is visible. Switching tabs or apps releases it, and MDN says browsers can refuse it, for example in power saving.

Why does my screen still turn off with a 10-minute timeout?

Check power saving, which can shorten the timeout, and whether a case covers the proximity sensor.

Keep Reading
Sources // Verified

Official docs

Timeout range, default and no-off rule: Samsung: Change the screen timeout and Samsung: Stop the screen brightness from dimming. Keep screen on while viewing, Smart stay and availability: Samsung: Stop the screen brightness from dimming, Samsung: Screen turns off while using Galaxy phone or tablet and Galaxy Tab A9+ user guide (Android 13 edition). Power saving and the proximity sensor: Samsung: Change the screen timeout and Samsung: Stop the screen brightness from dimming. Pixel path: Pixel Phone Help: screen and display settings. Stay awake: Android Developers: Configure on-device developer options. Wake lock requests, refusals, release and re-acquiring: MDN: Screen Wake Lock API and Chrome for Developers: Stay awake with the Screen Wake Lock API.

← All Tutorials Byteslip Apps

See more free browser games with leaderboards.