admin管理员组文章数量:1023554
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 badges3 Answers
Reset to default 4No, 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.
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 badges3 Answers
Reset to default 4No, 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.
本文标签: javascriptDetect memory exhaustion in the browser before it crashesStack Overflow
版权声明:本文标题:javascript - Detect memory exhaustion in the browser before it crashes - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745575407a2156987.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论