Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot read property 'location' of null" error in javascript #244

Closed
guillehorno opened this issue Feb 1, 2017 · 17 comments
Closed

"Cannot read property 'location' of null" error in javascript #244

guillehorno opened this issue Feb 1, 2017 · 17 comments

Comments

@guillehorno
Copy link

guillehorno commented Feb 1, 2017

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
@scotteknight
Copy link

scotteknight commented Feb 4, 2017

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?

@buffym
Copy link

buffym commented Feb 8, 2017

@savmac I tried your workaround and I'm still receiving the location null error. Did placement compared to other javascript (if any) in the head matter?

@nachomazzara
Copy link

+1 I'm having the same issue.

@scotteknight
Copy link

@buffym Is your project using Turbolinks? In my case it appeared as a conflict with Turbolinks since it only renders the body and not the head after the initial page load. All of my scripts were in the head except for Intercom's because of it's automatic insertion into the body which I didn't realize until I saw this error.

If you are not using turbolinks then it may be a different issue causing the error.

I'm not that great with javascript so I'm not really sure how to investigate it further. It could be similar to this pull request except fix it for the latest version of turbolinks. Maybe someone from the Intercom team can check it out?

@buffym
Copy link

buffym commented Feb 8, 2017

@savmac I am using Turbolinks. I load most of my page javascript before the closing body tag, and use "data-turbolinks-eval=false" to prevent Turbolinks from reloading it when it swaps things around. But, I moved the intercom js to the head as you suggested in here, but am still seeing the location null error in the frame js.

@nachomazzara
Copy link

nachomazzara commented Feb 8, 2017

I'm not using turbolinks an the error is still there

@scotteknight
Copy link

In case it helps the investigation, I just checked my history and initially I was using the latest version of turbolinks and definitely did not have this error. Weeks later I updated the intercom-rails gem from 0.2.30 to 0.3.4 and subsequently discovered this error.

@buffym
Copy link

buffym commented Feb 8, 2017

Thanks @savmac I'll look into rolling back my intercom-rails version (for now) and see if that helps.

@filipeperdigaosousa
Copy link

filipeperdigaosousa commented Mar 23, 2017

I'm still having this error. How can this be solved?

@volkanunsal
Copy link

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

@jfeust
Copy link

jfeust commented May 24, 2017

Bump on this. Can we please get this resolved? We're using Rails 5, Turbolinks 5, with turbolinks-cache-control set to no-cache.

Tons of these errors every day.

@kant01ne
Copy link
Contributor

kant01ne commented Jun 9, 2017

This should be fixed now. Can you confirm you don't see any Uncaught TypeError: Cannot read property 'location' of null anymore?

@filipeperdigaosousa
Copy link

This error has disapeard, but right now, I'm experiencing tons of undefined is not an object (evaluating 'e.userAgent')

@kant01ne
Copy link
Contributor

kant01ne commented Jun 9, 2017

I see you created another issue for this new problem. I'll close this issue as it is fixed.

@kant01ne kant01ne closed this as completed Jun 9, 2017
@rubendinho
Copy link
Contributor

@Skaelv - We are persistently seeing this error on production, and have been for close to a year. It seems to come and go - most recently it's affecting Chrome users on both Android and Windows.

We are running.
rails 5.1.4
turbolinks 5.0.3
intercom-rails 0.3.5

@ciihla
Copy link

ciihla commented Apr 14, 2018

Same issue here. I can confirm that disabling Turbolinks fixes the issue, but not sure if the problem is in Turbolinks or in https://js.intercomcdn.com/frame.1c4eb843.js
Just to clarify: The issue happens only if reloading layout (Going from one page with one layout to other page with different layout. Switching pages within the same layout is okay even with Turbolinks )

@giolazzareschi
Copy link

giolazzareschi commented Jul 4, 2018

Hi!

As the Turbolinks change pages we need update intercom before.

I could manage a workaround just playing "update" method right after boot it.

function renderIntercom() {
	try{Intercom("shutdown")}catch(e){};
	Intercom('boot', {  
		app_id: 'APP_ID',
		email: '[email protected]',
		created_at: +new Date,
		name: 'John Doe'
	});
	window.Intercom("update");
}

Hope it helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests