JavaScript to Bypass Google Chrome’s Memory Saver for App Tabs

Chrome is great. Fast, works well, extension library. But with that performance comes performance features, even ones you didn’t realize are running.

Memory Saver is one of those performance features. It keeps tabs that aren’t in focus from running and eating all of your memory.

Great if you didn’t want them to eat all of your memory – bad if the app should be running in the background and you didn’t want it to be paused. It tries to save your memory but the app you thought was running was suspended.

For developers, this is annoying. But I may have found a simple loophole for this. It’s not the best solution for a production app, but it works:

Play some silent/fake audio in the background, and it keeps the tab active. This solution may even work in other browsers too, and it even works with things like iFrames, web workers, Firefox (they have background time-outs too), Safari (they also throttle hidden page timers), and even energy settings on some computers.

The downside is, well, you see a little volume icon up in your tab.

So this is fine for local web apps you’ve built, but probably not in a production environment.

Here’s some example JS:

// Generate fake audio
(() => {
	  window.addEventListener('error', e => { e.preventDefault(); });
	  window.addEventListener('unhandledrejection', e => { e.preventDefault(); });
	  const start = () => {
		try {
		  const AudioCtx = window.AudioContext || window.webkitAudioContext;
		  if (!AudioCtx) return;

		  const ctx = new AudioCtx();
		  const osc = ctx.createOscillator();
		  osc.frequency.value = 20000;
	
		  const g = ctx.createGain();
		  g.gain.value = 0.0008;
	
		  osc.connect(g).connect(ctx.destination);
		  osc.start();
	
		  window.removeEventListener('pointerdown', start);
		  window.removeEventListener('keydown', start);
		  console.log('keep-alive running at –62 dB, 20 kHz');
		} catch (_) {}
	  };
	
	  ['pointerdown', 'keydown'].forEach(evt =>
		window.addEventListener(evt, start, { once: true })
	  );
	  ['pointermove', 'mousemove'].forEach(evt =>
		window.addEventListener(evt, start)
	  );
	})();
	

Now I realize this is a very limited fix for a very specific use case, but I thought it was interesting nevertheless and it happened to fix my issue with my local app’s tabs from being paused until they regain focus. Even with my memory saver turned completely off, this was still happening – until this bit of code.

Did this help you? Have a better method? Let’s get a convo started in the comments. Cheers!

What People Are Saying:

No comments yet. Be the first!

Leave a Reply

Copyright 2025, All rights reserved. Yadda yadda.