intercom-rails: "Cannot read property 'location' of null" error in javascript

Hi. I’ve recently integrated javascript error reporting and started to see some exceptions from the intercom javascript script. The error comes from https://js.intercomcdn.com/frame.2f08db79.js , line 24 column 701. It’s the definition of the function _getCurrentPage

r.prototype._getCurrentPage=function(){return window.location.href}

I’m not sure if this is normal, looks like in the context of the execution of this function window is undefined.

This is the complete stack trace:

File https://js.intercomcdn.com/frame.2f08db79.js line 24 col 701 in r._getCurrentPage
File https://js.intercomcdn.com/frame.2f08db79.js line 23 col 31744 in r._sendUserPresenceEvent
File https://js.intercomcdn.com/frame.2f08db79.js line 23 col 31549 in r._userPresence
File https://js.intercomcdn.com/frame.2f08db79.js line 23 col 30925 in r.setUserPresent
File https://js.intercomcdn.com/frame.2f08db79.js line 17 col 13232 in [anonymous]
File https://js.intercomcdn.com/frame.2f08db79.js line 17 col 4198 in [anonymous]
File https://js.intercomcdn.com/frame.2f08db79.js line 17 col 12460 in [anonymous]
File https://js.intercomcdn.com/frame.2f08db79.js line 29 col 5518 in [anonymous]
File https://js.intercomcdn.com/frame.2f08db79.js line 5 col 16073 in onUserPresent
File https://js.intercomcdn.com/frame.2f08db79.js line 17 col 16044 in l
File https://js.intercomcdn.com/frame.2f08db79.js line 17 col 16160 in HTMLDocument.h

Thanks!

Version info

  • intercom-rails version: 0.3.4
  • Rails version: 5.0.1

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 11
  • Comments: 17 (3 by maintainers)

Most upvoted comments

Is there any chance this will get fixed? I’m getting dozens of errors everyday from this library.

I am getting the same error in the chrome console: Uncaught TypeError: Cannot read property 'location' of null

I’ve narrowed it down to intercom and turbolinks (latest version 5.0.1) not working together, specifically when the browser’s back or forward button is used and turbolinks is rendering from cache.

Update: I was able to eliminate the error by manually inserting <%= intercom_script_tag %> into the head of the application layout instead of having intercom auto insert it before the closing </body> tag. With turbolinks, all assets need to be in the head since the body is replaced on each visit.

Maybe this isn’t necessarily a bug but should be documented in the readme for turbolinks users?