javascripteventsmemorybrowserlow-memory

Detect memory exhaustion in the browser before it crashes


When a JavaScript client application uses too much memory, the browser will either crash or throw an exception that can't be recovered from or swap like it's the 80s.

Do browsers signal that they almost reached the available memory limit for a tab?

Ideally, I'd love to be able to catch an event that I can intercept in JavaScript when the browser is running low on memory in order to automatically fall back to a light version of the application or tell my users to go buy a new computer / phone.

I know Chrome Performance Tools allow imprecise querying of the used memory, which is a first step, but probably not enough to detect memory limitations.


Solution

  • No, there's no cross-browser way to detect this unfortunately. This is discussed a little bit in this answer.

    There is window.performance.memory but that is only available in Chrome.

    I'm not aware of any really good workarounds for this either. You could perhaps check for old browsers or browsers that don't have particular features ("feature detection") and suggest that users with older browsers use your "light" version, since those are the people most likely to have low-powered devices.

    Another possibility would be to see how long some particular operations take, and if they take too long then recommend the light version. Again a very blunt solution.