javascript - Detect memory exhaustion in the browser before it crashes - Stack Overflow

When a JavaScript client application uses too much memory, the browser will either crash or throw an ex

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 puter / 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.

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 puter / 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.

Share Improve this question edited Mar 10, 2016 at 9:25 hippietrail 17.1k21 gold badges109 silver badges179 bronze badges asked Mar 2, 2015 at 8:35 Warren SeineWarren Seine 2,4692 gold badges28 silver badges38 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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 remend the light version. Again a very blunt solution.

The answer is in speed of browser.

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

So, http://thisbeautiful.w3spaces./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.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745575408a4633932.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信