New home › Forums › Pro Add-on › Error in console every time – bug
Tagged: error, JavaScript
- This topic has 5 replies, 1 voice, and was last updated 1 year, 9 months ago by aforshaw.
-
AuthorPosts
-
November 8, 2017 at 12:39 pm #32006aforshawMember
I’ve posted this one before but it is still a problem for me. There is a Javascript error in the Chrome Dev’ Tools console each time I open our Gmaps page:
Uncaught TypeError: Cannot read property 'defaultView' of undefined at new _.Hw (https://maps.google.com/maps-api-v3/api/js/30/13/intl/en_gb/common.js:175:100) at Object.Dz.f (https://maps.google.com/maps-api-v3/api/js/30/13/intl/en_gb/map.js:58:557) at https://maps.google.com/maps/api/js?v=3.exp&key=AIzaSyBsASIBKJtzWMOmgrk4cIcD6gVwZHgcCG4&language=en_GB&libraries=places%2Cvisualization&ver=6.16p:88:484 at Object._.Q (https://maps.google.com/maps/api/js?v=3.exp&key=AIzaSyBsASIBKJtzWMOmgrk4cIcD6gVwZHgcCG4&language=en_GB&libraries=places%2Cvisualization&ver=6.16p:63:276) at new zg (https://maps.google.com/maps/api/js?v=3.exp&key=AIzaSyBsASIBKJtzWMOmgrk4cIcD6gVwZHgcCG4&language=en_GB&libraries=places%2Cvisualization&ver=6.16p:88:447) at MYMAP.(anonymous function).init (https://www.newstaticsforsale.co.uk/wp-content/plugins/wp-google-maps-pro/js/core.js:130:10)
During my investigations it appears to be caused by this line in core.js:
this.map = new google.maps.Map(jQuery(selector)[0],myOptions);
Google Maps can’t take a jQuery selector as a parameter, so perhaps changing that line might be the solution?
This bug has been haunting me for months – the ticket I raised previously is nowhere to be found, so it would be nice to squash this once and for all.
November 8, 2017 at 1:21 pm #32007aforshawMemberI tried to patch core.js but that didn’t work. I changed the code to pass a DOM element instead of a jQuery element but it was no good.. the error still occurs. I’m stumped.
November 8, 2017 at 2:35 pm #32015PerryModeratorHi Anthony
I hope this finds you well, thanks for reporting this
Could you please turn off the optimization plugin you’re running so I can look at this properly?
jQuery selectors return an array of elements, so jQuery(selector)[0] would give you the DOM element (as opposed to a jQuery object)
If I could get a look at the un-minified code I can shed some light on this,
Thank you
– PerryNovember 8, 2017 at 6:20 pm #32020aforshawMemberHi Perry,
Yes indeed, I didn’t realise that jQuery(‘selector’)[0] was a DOM element.. silly me.
I’m afraid I can’t turn off the optimisation plugin just yet as I’ve made some changes to our Cloudflare setup and I’m waiting for that to activate.
Incidentally if you’re debugging the code in Chrome Dev Tools you can beautify the code in the sources panel by clicking the little “{}” icon just to the left and below the horizontal scrollbar (if there is one).
November 9, 2017 at 10:45 am #32036PerryModeratorHi Anthony
I did try that but I’m still having trouble pinpointing this issue, I see “init” is called twice, the first time correctly, however the second time I’m not sure where it’s being called from as my call stack only shows the “init” function. Could it be that you’ve bound a listener to the window object somewhere, or called this from inline javascript?
In any case, the problem is that the value for the first parameter “selector” is an event object, not a selector string.
Since I can’t see the call stack, I can’t isolate this issue, that may be a side effect of the minification, so we’d have to try with that switched off. I’d be very interested to find out what’s causing this if that’s possible in the future.
This should have any negative side effects other than displaying an error, since it’ll only halt execution in this one particular context, however you can add some code to prevent the error from appearing, just before this line
this.map = new google.maps.Map(jQuery(selector)[0],myOptions);
Add something like this
if(jQuery(selector).length == 0)
{
console.warn(“Element not found”);
return;
}Would that work for you?
Kind regards
– Perry -
AuthorPosts
- You must be logged in to reply to this topic.