7

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.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Warren Seine
  • 2,311
  • 2
  • 25
  • 38

3 Answers3

4

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.

Community
  • 1
  • 1
Andrew Magee
  • 6,506
  • 4
  • 35
  • 58
  • Thanks for confirming my intuition. I'll mark this as answered, hoping I'll be able to switch to a better answer at some point in the future ! – Warren Seine Mar 02 '15 at 13:48
0

The answer is in speed of browser.

It doesn't show memory very correctly to prevent fingerprinting exactnes.

So, http://thisbeautiful.w3spaces.com/notbad.htm contains code to loop with an interval like this:

JavaScript:

momentum=Date.now();for(itr=1;itr<770;itr++){};momentumTwo=Date.now()-momentum;if(momentumTwo>3){ //take action
     } //and every second if you wrap in into an interval

Reference this to get example.

Summary:the code sees how long it takes to loop things and, if crash, take action.

-1

Using a program that monitors the browser system should be a better solution, as browsers themselves are not fully able do such a thing.

iabuaz
  • 152
  • 9