Google Maps toDataURL does not seem to work

I am trying to use toDataURL() to take a snapshot of the map. I used this very basic code to test if it works.

console.log("Calling toDataURL()");
  data => {
    console.log("Success: " + data);
  exc =>

I waited until the map was fully loaded and manually invoked the code. But it did not seem to work. The output was

Calling toDataURL()

and that was all. What have I done wrong?