Created
February 16, 2015 19:28
-
-
Save cgbystrom/7e734d988664f1b89ff5 to your computer and use it in GitHub Desktop.
Revisions
-
cgbystrom created this gist
Feb 16, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ function hookCanvasGetContext () { var ctxFns = [ 'fillRect', 'save', 'restore', 'scale', 'rotate', 'translate', 'transform', 'setTransform', 'resetTransform', 'createLinearGradient', 'createRadialGradient', 'createPattern', 'clearRect', 'strokeRect', 'beginPath', 'fill', 'stroke', 'drawFocusIfNeeded', 'clip', 'isPointInPath', 'isPointInStroke', 'fillText', 'strokeText', 'measureText', 'drawImage', 'createImageData', 'getImageData', 'putImageData', 'getContextAttributes', 'setLineDash', 'getLineDash', 'setAlpha', 'setCompositeOperation', 'setLineWidth', 'setLineCap', 'setLineJoin', 'setMiterLimit', 'clearShadow', 'setStrokeColor', 'setFillColor', 'drawImageFromRect', 'setShadow', 'closePath', 'moveTo', 'lineTo', 'quadraticCurveTo', 'bezierCurveTo', 'arcTo', 'rect', 'arc', 'ellipse', 'scrollPathIntoView', 'addHitRegion', 'removeHitRegion', 'clearHitRegions', 'isContextLost' ]; var origGetContext = HTMLCanvasElement.prototype.getContext; var callsMade = []; function hookFunc (ctx, name) { var origFn = ctx[name]; ctx[name] = function () { callsMade.push([name, arguments]); return origFn.apply(this, arguments); }; } window.printCanvasCalls = function () { callsMade.forEach(function (c) { console.log(c[0], c[1]); }) }; HTMLCanvasElement.prototype.getContext = function () { var ctx = origGetContext.apply(this, arguments); ctxFns.forEach(function (fnName) { hookFunc(ctx, fnName); }); return ctx; } }