save() not working on any canvas?

I'm running 05.js 0.4.6 and am attempting the save() function to download a image from the canvas and am getting the error: Uncaught TypeError: Cannot read property 'toDataURL' of undefined

Example of JS (not my actual javascript being used):

function setup() {

//Creating the webpage interface 
var canvas = createCanvas(1280, 1280);

//Variable center of screen
centerx = width/2;
centery = height/2; 

//Creating the # of authors input (will be replced with CSV data)
but = createInput("10");

This is being drawn within the HTML. Running this just leads to that error. What should I do to fix? Thanks!


  • edited July 2015

    I was able to make it run it w/o error by moving save() into draw().
    And also by explicitly passing the canvas' reference to it:

    function setup() {
      const cnv = createCanvas(320, 240).position(0, 0);
      but = createInput('Type in here...');
      but.position(200-176 >> 1, 10);
    function draw() {
      save(cnv, 'test.png');

    Although I still think it's very buggy and should be reported here:

    Don't forget to mention your thread here there! O:-)

Sign In or Register to comment.