javascriptgoogle-chromeandroid-browseraddthis

addthis_widget.js throwing Cannot read property '_pmh' of null error on Android and Chrome


I am using a JavaScript error logging tool to log any JavaScript errors on my mobile site and I am seeing a large number (22,000 in under a month) of this error:

Uncaught TypeError: Cannot read property '_pmh' of null

I can see from the addthis_widget.js code that it is originating from that script.

I can also tell that it only affects mobile Android and Google Chrome browsers, these in particular:

Android 4, Android 4.1, Android 4.2, Chrome 11, Chrome 18, Chrome 25, Chrome 26, Chrome 27, Chrome Mobile 18, Chrome Mobile 25, Chrome Mobile 26

I am using the following external JavaScript include:

http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b6adff375a64db9

and have the following configuration object set:

<script type="text/javascript">
    var addthis_config = {
        data_ga_property: 'UA-18721873-1', // real GA profile hidden for privacy purposes           
        data_ga_social: true
    };
</script>

Is there anything I can do to prevent this error from occuring so many times on these browsers?


Solution

  • I have located the cause of this issue and it is down the following code.

    if (window.addthis) {
       window.addthis = null;
       window._adr = null;
       window._atc = null;
       window._atd = null;
       window._ate = null;
       window._atr = null;
       window._atw = null;   
    }
    

    This was an attempt to cleanup the objects lying around when moving between pages dynamically to prevent memory issues.

    addThis now provide support for this problem, their support department sent me the following link:

    http://www.addthis.com/blog/2013/05/07/a-brief-history-of-using-addthis-dynamically/#.Uklx4RCKyas

    and the following explanation/information:

    Along with other information from my peers and such, I've come up with the proper code which should be executed when moving from virtual page to virtual page such as in your mobile application. Rather than nulling any of the AddThis related objects, they must be left alone.

    When the page URL or Title (or any other AddThis configuration option) that you want to be used by our buttons changes, you should execute our method:

    addthis.update(type, key, value)

    It takes the three parameters: type, key, value.

    Type is either "share" or "config". The key is the same key you would set according to our API documentation. What you likely need to know are just the two keys: "url" and "title". The value is of course the value you want those options to have.

    After you have updated all of the options you need to update using that method, you need to invoke this method:

    addthis.toolbox(cssSelector)

    The cssSelector is usually going to be ".addthis_toolbox" but if for some reason you don't want to refresh all of your toolboxes, you can be more specific about it.

    Once you have made those changes to your code, I believe that our tools will work properly for you and that there will be no more "null object" related javascript errors.

    You can look at this JSFiddle to see an example of dynamically changing content: http://jsfiddle.net/j5addthis/r6Utv/