How to convert image(static openstreetmap) into base64 string using javascript

I need to convert a static map image.I found the following code:

function toDataURL(url, callback) {
  var xhr = new XMLHttpRequest();
  xhr.onload = function() {
    var reader = new FileReader();
    reader.onloadend = function() {
  };'GET', url);
  xhr.responseType = 'blob';

toDataURL('', function(dataUrl) {
  console.log('RESULT:', dataUrl)

The problem is that any other image is generated very well, but from this link:,20,3744&zoom=10&size=640×640&maptype=mapnik&format=png

This does not work 🙁

Link to items such as DOM works, but this conversion is not working. Do you have any idea what’s wrong with my link?

Thanks for any replies 🙂

Source: stackoverflow-javascript