{"id":19029019,"date":"2026-09-25T07:35:50","date_gmt":"2026-09-25T07:35:50","guid":{"rendered":"https:\/\/wordpress.org\/support\/?post_type=topic&#038;p=19029019"},"modified":"2026-09-25T07:36:54","modified_gmt":"2026-09-25T07:36:54","slug":"popup-widget-uncaught-typeerror-callback-is-not-a-function-in-load_tlib","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/popup-widget-uncaught-typeerror-callback-is-not-a-function-in-load_tlib\/","title":{"rendered":"Popup widget: &#8220;Uncaught TypeError: callback is not a function&#8221; in load_tlib()"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I found a JavaScript error in the popup widget (wp-content\/plugins\/gtranslate\/js\/popup.js):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Uncaught TypeError: callback is not a function<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Cause<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">load_tlib() is used in two ways: it is called with a callback function, and it is also registered directly as an event listener:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">e.addEventListener(&#8216;pointerenter&#8217;, load_tlib);<br \/>e.addEventListener(&#8216;focusin&#8217;, load_tlib);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When it is used as a listener, the browser passes the native Event object as the first argument. The current checks only test for truthiness (<code>if (callback)<\/code> and <code>callback &amp;&amp; callback()<\/code>), and an Event object passes that test even though it is not callable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This causes two problems:<\/p>\n\n\n\n<ol>\n<li>If the library is already loaded (the else branch), <code>callback()<\/code> is called on a MouseEvent\/FocusEvent and throws &#8220;callback is not a function&#8221;.<\/li>\n\n\n\n<li>If the library is not loaded yet, the Event object is registered as a &#8216;load&#8217; listener on the script element. It is not a valid listener (it has no handleEvent method), so an error is also reported when the script finishes loading.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Steps to reproduce<\/strong><\/p>\n\n\n\n<ol>\n<li>Open any page with the GTranslate popup widget.<\/li>\n\n\n\n<li>Hover over the language switcher. This loads lib.min.js.<\/li>\n\n\n\n<li>Move the pointer away and hover again, or tab into the switcher.<\/li>\n\n\n\n<li>Check the browser console: &#8220;Uncaught TypeError: callback is not a function&#8221;.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Suggested fix<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check that the argument is actually a function before using it:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">function load_tlib(callback) {<br \/>if (!window.gt_translate_script) {<br \/>window.gt_translate_script = document.createElement(&#8216;script&#8217;);<br \/>gt_translate_script.src = &#8216;https:\/\/cdn.gtranslate.net\/widgets\/latest\/lib.min.js&#8217;;<br \/>document.body.appendChild(gt_translate_script);<br \/>if (typeof callback === &#8216;function&#8217;)<br \/>gt_translate_script.addEventListener(&#8216;load&#8217;, callback, {once: true});<br \/>} else {<br \/>if (typeof callback === &#8216;function&#8217;) callback();<br \/>}<br \/>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Environment<\/strong><\/p>\n\n\n\n<ul>\n<li>WordPress version: (local development)<\/li>\n\n\n\n<li>Widget type: Popup<\/li>\n\n\n\n<li>Reproduced in Chrome\/Chromium; likely affects all browsers<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks!<\/p>\n","protected":false},"template":"","class_list":["post-19029019","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19029019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19029019\/revisions"}],"predecessor-version":[{"id":19029021,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19029019\/revisions\/19029021"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19029019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}