Skip to content

TypeError: Cannot read property 'target' of undefined #593

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

Closed
gabn88 opened this issue May 26, 2016 · 15 comments
Closed

TypeError: Cannot read property 'target' of undefined #593

gabn88 opened this issue May 26, 2016 · 15 comments

Comments

@gabn88
Copy link

gabn88 commented May 26, 2016

This happens at line 707 of raven.js for me while testing things.

browser = Chrome Mobile 42.0, level = error, logger = javascript, os = Android 4.4.2

Not exactly sure why it happens, maybe someone here has an idea?

@gabn88
Copy link
Author

gabn88 commented May 26, 2016

Can confirm it also happens on Chrome Mobile 45.0 and 46.0.

@gabn88
Copy link
Author

gabn88 commented May 26, 2016

I think, but are not sure, that error within my javascript is not created by an event such as a click, but just by code that is executed on page load. The tricky part is that I cannot reproduce any error in chrome on linux. I have seen the Sentry event now for 60 times already, so it is reproducable on the mobile (Android) device(s). Will continue investigate this...

@benvinegar
Copy link
Contributor

What version of Raven.js? The latest master (3.0.4) doesn't have a target near line 707. Were you loading Raven.js from the CDN (e.g. cdn.ravenjs.com)?

@gabn88
Copy link
Author

gabn88 commented Jun 1, 2016

It has evt.target in the dist of this repo? Ah, in the src it is this part:

       self._lastCapturedEvent = evt;
        var elem = evt.target;

        var target;

Around line 635

@gabn88
Copy link
Author

gabn88 commented Oct 31, 2016

Any news on this? I had already 174k of these errors in 5 months time..

@benvinegar
Copy link
Contributor

@gabn88 – it's hard for me to make progress on this without a page to reproduce the error.

I suppose I can just bail out if there's no target on evt, but I'm not comfortable making that change without seeing the error that triggered it first (i.e. how did evt become undefined in a basic click/keypress handler?).

@gabn88
Copy link
Author

gabn88 commented Nov 1, 2016

It is not a basic click/keypress handler. There are some timers running on the webapp that trigger events when the time is reached. So practically speaking, there is no target when the event triggers.

But I think there are many cases where an event is not triggered by a click/keypress/touchstart, etc...
Sometimes even a reload of the page can trigger an event, so that it just executes on page load.

@zanona
Copy link

zanona commented Nov 29, 2016

Same error here guys! there are no errors being triggered on the page without sentry, however this same error on raven pops up when activating sentry.

Stack: Web Components
Browser: Chrome 54
Raven Load method: https://cdn.ravenjs.com/3.8.0/raven.min.js

screen shot 2016-11-29 at 15 55 54

The bit that is causing the error on Raven is as commented out below. I had to use another alternative which is very odd.

screen shot 2016-11-29 at 21 13 13

@LewisJEllis
Copy link
Contributor

Your failing example looks like a classic case of not binding this. This will do what you want:

setTimeout(this.onOverlayClick.bind(this), 100);

as will this:

var self = this;
setTimeout(function () { self.onOverlayClick(); }, 100);

as does your example with the arrow function thanks to how arrow functions handle this binding.

Just doing

setTimeout(this.onOverlayClick, 100);

will not bind this, and then things get weird from there. I'm not exactly sure, though, why the eventual outcome is this error specifically; @zanona do you have a minimum reproducing HTML page that we can play with it on?

@zanona
Copy link

zanona commented Nov 30, 2016

Thanks @LewisJEllis, that’s very insightful.
There are two things that are confusing me a bit.

  1. I am already binding all the class methods to its instance as this on the framework side;
  2. No errors are throw without sentry and the functionality works as expected?

In the end raven error is not blocking any functionality since the methods still works just as fine, but seeing those errors throw in there was a bit strange.

I will to see if I can reproduce that in isolation and provide you with an example anytime soon.

@Sija
Copy link
Contributor

Sija commented Nov 30, 2016

@LewisJEllis if I understand correctly JS6 fat arrow => binds receiver to this which should be the case.

@LewisJEllis
Copy link
Contributor

@Sija - yes, I indicated that in my previous comment/linked to the MDN page on that behavior - that's why zanona's snippet in the screenshot doesn't trigger the problem

@zanona - interesting; at best this is a confusing scenario for users to debug, and at worst it's a bug in raven-js. It might be a case of "error elsewhere ends up looking like error in raven-js" (like in #756 for example), but if everything works as expected without raven-js then I can't be sure of that. Either way there's something to improve, so please do let me know if you can provide a repro (even if it's not necessarily small/simple).

@zanona
Copy link

zanona commented Nov 30, 2016

Thansk @LewisJEllis will do.
I have event tried to wrap the error in a try…catch but it was getting anything from that and the error still being displayed on raven, so that is indeed strange.

I will hopefully be able to provide a reproduction soon. Thanks

@Sija
Copy link
Contributor

Sija commented Nov 30, 2016

@LewisJEllis true! I missed that part 😐

@kamilogorek
Copy link
Contributor

Closing due to long inactivity. Please feel free to reopen this issue if it's still relevant in any way.

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

6 participants