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 characters
| let png = canvas.toDataURL(); // default png | |
| let jpeg = canvas.toDataURL('image/jpg'); | |
| let webp = canvas.toDataURL('image/webp'); |
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 characters
| let image = new Image(); | |
| image.onload = () => { | |
| let canvas = document.createElement('canvas'); | |
| canvas.widht = width; | |
| canvas.height = height; | |
| let context = canvas.getContext('2d'); | |
| // draw image in canvas starting left-0 , top - 0 |
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 characters
| let URL = window.URL || window.webkitURL || window; | |
| let blobURL = URL.createObjectURL(blob); |
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 characters
| let outerHTML = clonedSvgElement.outerHTML, | |
| blob = new Blob([outerHTML],{type:'image/svg+xml;charset=utf-8'}); |
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 characters
| let clonedSvgElement = svgElement.cloneNode(true); | |
| // true for deep clone |
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 characters
| var svgElement = document.getElementById('svg_element'); | |
| let {width, height} = svgElement.getBBox(); |
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 characters
| window.onerror = function(e) { | |
| console.log("error handled", e); | |
| } | |
| function funcWithError() { | |
| a; // a is not defined | |
| } | |
| function test() { | |
| funcWithError(); | |
| console.log("hi"); // this will not be executed | |
| } |
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 characters
| function callback() { | |
| try { | |
| // error code | |
| }catch | |
| console.log("Error caught") ; | |
| } | |
| } | |
| function test() { | |
| setTimeout(callback, 1000); | |
| } |
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 characters
| function callback() { | |
| // error code | |
| } | |
| function test() { | |
| try { | |
| setTimeout( callback , 1000); | |
| } catch (e) { | |
| console.log( "not executed" ); | |
| } | |
| } |
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 characters
| try { | |
| // code with bug; | |
| } catch { | |
| // catch without exception argument | |
| } |