title: How to find what's wrong using a remote js file (Bing Maps API)
body: <p>This issue is hard to explain, I post it here because I don't know what to do.</p>
  
  <p>I have a Bing map v8 using javascript API, it works using many remote files.</p>
  
  <p>I need to show some custom html elements over the map, I can't do it using normal pushpins, markers or overlays, so I found in a blog a way to do it using "custom overlays", its works fine , it's a prototipe object, it's have an HTML element to send to the API.</p>
  
  <p>Sadly it worked in some files but suddenly give me an error in my last code, I can't figure how to find what is wrong, I can not debug it or comment it because I can not edit those remote files (they are in a microsoft server).</p>
  
  <p>I made this jsfiddle to show the error: <a href="https://jsfiddle.net/2x1nh8pa/2/" rel="nofollow noreferrer">https://jsfiddle.net/2x1nh8pa/2/</a></p>
  
  <pre><code>var maps='microsoft';
  
  var marker=new Array();
  
  window.startm = function(){
      var latlng=new Microsoft.Maps.Location(-20.976,-68.709);
      var myOptions={
          enableClickableLogo: false,
          enableSearchLogo: false,
          customizeOverlays: true,
          zoom: 16,
          center: latlng,
          mapTypeId: Microsoft.Maps.MapTypeId.aerial
      };
      map=new Microsoft.Maps.Map(document.getElementById("map_canvas"), myOptions);
      addOverlays();
  }
  function addOverlays() {
      // This is the prototype!
      function CustomMarker(latlng, map, cont, clas, title, args) {
          this.latlng = latlng;
          this.args = args;
          this.cont = cont;
          this.clas = clas;
          this.title = title;
          if(maps=='google')  this.setMap(map);
      }
    CustomMarker.prototype = new Microsoft.Maps.CustomOverlay();
    CustomMarker.prototype.draw = function() {
          var self = this;
          var div = this.div;
          //
          if (!div) {
              div = this.div = document.createElement('div');
  
              div.innerHTML=this.cont;
              div.className = this.clas;
              div.style.position = 'absolute';
              div.style.cursor = 'pointer';
  
              div.title=this.title;
  
              div.style.marginLeft= (typeof(self.args.anchorLft) !== 'undefined'?self.args.anchorLft:'-36px');
              div.style.marginTop = (typeof(self.args.anchorTop) !== 'undefined'?self.args.anchorTop:'-36px');
              this.setHtmlElement(div);
          //  }
          }
  
          var point = radar.tryLocationToPixel(this.latlng, Microsoft.Maps.PixelReference.control);
  
          if (point) {
              div.style.left = point.x + 'px';
              div.style.top = point.y + 'px';
          }
      };
  
      var latlng=new Microsoft.Maps.Location(-20.976,-68.709);
      var pictureLabel=new Array();
      var pictureLabelpoi=new Array();
                          latlng=new Microsoft.Maps.Location(-20.97599,-68.70899);
                          pictureLabel[1] = document.createElement("img");
                          pictureLabel[1].src = "https://bestanimations.com/Signs&amp;Shapes/Arrows/animated-green-arrow-down2.gif";
                          pictureLabel[1].id = "img1";
  
                              marker[1] = new CustomMarker(
                                  latlng,
                                  map,
                                  pictureLabel[1].outerHTML, 
                                  "arrowclass img1",
                                  '2016-08-09 12:08:14',
                                  {
                                      anchorTop:'-8px',
                                      anchorLft:'-8px'
                                  }
                              )
                              map.layers.insert(marker[1]);//this line causes the error
  }
  $('input[type=button]').click( function() {
  startm();
  });
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Failed to execute 'insertBefore' on 'Node':
    parameter 1 is not of type 'Node'.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/JDQ5y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JDQ5y.png" alt="Error found using chrome"></a></p>
  
  <p>-------------- edit to add example -----------</p>
  
  <p>I made a new jsfiddle showing a different example, this one works with no error, I dont know why it's different: <a href="https://jsfiddle.net/tfcefsL4/" rel="nofollow noreferrer">https://jsfiddle.net/tfcefsL4/</a></p>