title: Image paste into contenteditable div working for a wrong reason in Safari
body: <p>In my code, I am generating a thumbnail of the image being drag-dropped or copy-pasted. Drag and drop is not a problem but with copy-paste, I can see an error in Safari (snapshot below) <em>but still the thumbnail is generated!</em></p>
  <p><strong>Error:</strong>
  <a href="https://i.stack.imgur.com/0IJ6n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0IJ6n.png" alt="enter image description here" /></a></p>
  <p><strong>Relevant snippet of my code:</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>document.getElementById('target').addEventListener('paste', function(event){
    console.log("pasted!", event);
    this.style.background='green';
  
    // get pasted data; Source: http://codingmiles.com/pasting-image-contenteditable-div/
    var pastedData = event.clipboardData.items[0];
  
    console.log("pastedData",pastedData);
  
    // If the clipboard data is of type image, read the data
    if(pastedData.type.indexOf("image") === 0) {
      console.log('calling thumbnail function'); // does not show up in the console! o.O
      composeThumbnail(pastedData.getAsFile()); // this still works!
    }
  });
  
  function composeThumbnail(file) { // source: https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
  
    if (!/^image\//.test(file.type)) { // if not an image; 0 since we take only 1 image, if multiple dragged at once, consider only the first one in the array
      console.log('ERROR: Not an image file.');
      return false;
    }
  
    // compose an &lt;img&gt; for the thumbnail
    var thumbnailImage = document.createElement("img");
    thumbnailImage.file = file;
    document.getElementById('target').appendChild(thumbnailImage);
  
    var reader = new FileReader();
  
    reader.onload = (function(thumbnailImage) {
      // this image is part of the data, so send typing notification to the agent
      return function(event) {
        thumbnailImage.src = event.target.result;
      };
    })(thumbnailImage);
  
    reader.readAsDataURL(file);
  
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#target{
    width: 100%;
    height: 200px;
    border: 2px solid black;
    border-radius: 5px;
    background: transparent;
    padding: 15px;
  }
  
  #target img{
    height: 25%;
    width: auto;
    vertical-align: middle;
    border-radius: 5px;
    padding: 5px;
  }
  
  #target *{
    vertical-align: text-top;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="width=device-width"&gt;
      &lt;title&gt;JS Bin&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
      &lt;div id="target" contenteditable="true"&gt;&lt;/div&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>As mentioned in the comments, I have used <a href="https://web.archive.org/web/20161206052921/http://codingmiles.com:80/pasting-image-contenteditable-div/" rel="nofollow noreferrer">this resource</a> for the paste event handler.</p>
  <p>My Safari version is 9.1 and I am on Mac OS X El Capitan.</p>
  <p>Why is the thumbnail still being generated? What am I missing here?</p>