此页面上的活动WebGL上下文太多,最旧的上下文将丢失.[dedup.min.js] [英] There are too many active WebGL contexts on this page, the oldest context will be lost. [dedup.min.js]
问题描述
我仅在Safari浏览器上遇到了这个严重的错误.不知道为什么.我正在使用AngularJS1.3.x.
I am getting this wiered error only on Safari browser. Don't know why. I am using AngularJS 1.3.x.
所以我如何检测哪些库可能正在使用此库.为什么只在野生动物园中出现此错误?是否可以通过JS启用或禁用WebGL?
So how do I detect which libraries may be using this. And why only in safari I get this error ? Is there a way via JS to enable or disable WebGL ?
推荐答案
将其放在HTML的顶部吗?
Put this at the top of your HTML?
<script>
HTMLCanvasElement.prototype.getContext = (function(origFn) {
var bannedTypes = {
"webgl": true,
"webgl2": true,
"experimental-webgl":, true,
};
return function() {
var type = arguments[0];
return bannedTypes[type]
? null
: origFn.apply(this, arguments);
};
}(HTMLCanvasElement.prototype.getContext));
</script>
只要它出现在任何其他脚本之前,它就应该阻止webgl.
As long as this appears before any other scripts it should block webgl.
以上脚本的更改替换了 someCanvas.getContext
函数,因此,当其他一些JavaScript尝试创建"webgl"上下文时,它将返回 null
,这意味着创建上下文失败.否则,如果JavaScript请求其他类型的上下文,它将调用原始的 getContext
函数.
The script above changes replaces the function someCanvas.getContext
so that when some other JavaScript tries to create a "webgl" context it returns null
which means creating the context fails. Otherwise if JavaScript asks for a different kind of context it calls the original getContext
function.
只要首先执行此脚本,它就应防止页面上的其他JavaScript创建webgl上下文.它不会阻止iframe中的JavaScript创建上下文.您需要为每个iframe添加相同的解决方案.
As long as this script is executed first it should prevent other JavaScript on the page from creating a webgl context. It won't prevent JavaScript in iframes from creating contexts. You'd need to add the same solution to each iframe.
这篇关于此页面上的活动WebGL上下文太多,最旧的上下文将丢失.[dedup.min.js]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!