There are too many active WebGL contexts on this page, the oldest context will be lost. [dedup.min.js]

我怕爱的太早我们不能终老 提交于 2019-12-24 21:25:25

问题


I am getting this wiered error only on Safari browser. Don't know why. I am using AngularJS 1.3.x.

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 ?


回答1:


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>

As long as this appears before any other scripts it should block webgl.

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.

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.



来源:https://stackoverflow.com/questions/52464621/there-are-too-many-active-webgl-contexts-on-this-page-the-oldest-context-will-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!