[Solved] Why does calling ctx.clearRect() crash page?

I have a painting app that works perfectly, except when I try to clear the canvas. When I click on the “Clear” button, instead of erasing the canvas, my page completely disappears. If I hover over it with my mouse, it says “cdpn.io refused to connect.” This seems bizarre. How can I fix this? Please see code at: https://codepen.io/velvetstar/pen/WNELxLB?editors=0010

Calling ctx.clearRect() is not your problem. The problem is, you aren’t stopping the button from doing what buttons want to do.


I forked your code and added that line (and comments, so you can see what I mean): https://codepen.io/snowmonkey/pen/mdMgVdw?editors=0010

Thank you so much!!!