Advertisement
A_GUES

Nothing

Oct 15th, 2023
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1.  
  2. var spector;
  3. var captureOnLoad = false;
  4. var captureOffScreen = false;
  5. window.__SPECTOR_Canvases = [];
  6.  
  7. (function() {
  8. var __SPECTOR_Origin_EXTENSION_GetContext = HTMLCanvasElement.prototype.getContext;
  9. HTMLCanvasElement.prototype.__SPECTOR_Origin_EXTENSION_GetContext = __SPECTOR_Origin_EXTENSION_GetContext;
  10.  
  11. if (typeof OffscreenCanvas !== 'undefined') {
  12. var __SPECTOR_Origin_EXTENSION_OffscreenGetContext = OffscreenCanvas.prototype.getContext;
  13. OffscreenCanvas.prototype.__SPECTOR_Origin_EXTENSION_OffscreenGetContext = __SPECTOR_Origin_EXTENSION_OffscreenGetContext;
  14.  
  15. OffscreenCanvas.prototype.getContext = function () {
  16. var context = null;
  17. if (!arguments.length) {
  18. return context;
  19. }
  20.  
  21. if (arguments.length === 1) {
  22. context = this.__SPECTOR_Origin_EXTENSION_OffscreenGetContext(arguments[0]);
  23. if (context === null) {
  24. return context;
  25. }
  26. }
  27. else if (arguments.length === 2) {
  28. context = this.__SPECTOR_Origin_EXTENSION_OffscreenGetContext(arguments[0], arguments[1]);
  29. if (context === null) {
  30. return context;
  31. }
  32. }
  33.  
  34. var contextNames = ["webgl", "experimental-webgl", "webgl2", "experimental-webgl2"];
  35. if (contextNames.indexOf(arguments[0]) !== -1) {
  36. // context.canvas.setAttribute("__spector_context_type", arguments[0]);
  37. // Notify the page a canvas is available.
  38. var myEvent = new CustomEvent("SpectorWebGLCanvasAvailableEvent");
  39. document.dispatchEvent(myEvent);
  40. this.id = "Offscreen";
  41. window.__SPECTOR_Canvases.push(this);
  42.  
  43. if (captureOnLoad) {
  44. // Ensures canvas is in the dom to capture the one we are currently tracking.
  45. if (false) {
  46. spector.captureContext(context, 500, false, false);
  47. captureOnLoad = false;
  48. }
  49. }
  50. }
  51.  
  52. return context;
  53. }
  54. }
  55.  
  56. HTMLCanvasElement.prototype.getContext = function () {
  57. var context = null;
  58. if (!arguments.length) {
  59. return context;
  60. }
  61.  
  62. if (arguments.length === 1) {
  63. context = this.__SPECTOR_Origin_EXTENSION_GetContext(arguments[0]);
  64. if (context === null) {
  65. return context;
  66. }
  67. }
  68. else if (arguments.length === 2) {
  69. context = this.__SPECTOR_Origin_EXTENSION_GetContext(arguments[0], arguments[1]);
  70. if (context === null) {
  71. return context;
  72. }
  73. }
  74.  
  75. var contextNames = ["webgl", "experimental-webgl", "webgl2", "experimental-webgl2"];
  76. if (contextNames.indexOf(arguments[0]) !== -1) {
  77. context.canvas.setAttribute("__spector_context_type", arguments[0]);
  78. // Notify the page a canvas is available.
  79. var myEvent = new CustomEvent("SpectorWebGLCanvasAvailableEvent");
  80. document.dispatchEvent(myEvent);
  81.  
  82. if (captureOffScreen) {
  83. var found = false;
  84. for (var i = 0; i < window.__SPECTOR_Canvases.length; i++) {
  85. if (window.__SPECTOR_Canvases[i] === this) {
  86. found = true;
  87. break;
  88. }
  89. }
  90. if (!found) {
  91. window.__SPECTOR_Canvases.push(this);
  92. }
  93. }
  94.  
  95. if (captureOnLoad) {
  96. // Ensures canvas is in the dom to capture the one we are currently tracking.
  97. if (this.parentElement || false) {
  98. spector.captureContext(context, 500, false, false);
  99. captureOnLoad = false;
  100. }
  101. }
  102. }
  103.  
  104. return context;
  105. }
  106. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement