Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Cordova pause event error from a null target #323

Closed
adamdbradley opened this issue Apr 14, 2016 · 5 comments
Closed

Cordova pause event error from a null target #323

adamdbradley opened this issue Apr 14, 2016 · 5 comments
Assignees

Comments

@adamdbradley
Copy link

Cordova fires a pause event when the app is put into the background, but this error is thrown from within patchViaCapturingAllTheEvents():
image

It looks as though event.target is null:
image

This only happens on Cordova's pause event, but is not a problem with the others:
https://cordova.apache.org/docs/en/latest/cordova/events/events.html#pause

@mhevery
Copy link
Contributor

mhevery commented Apr 14, 2016

@juliemr could you look at this?

@juliemr
Copy link
Member

juliemr commented Apr 14, 2016

This is the easy fix: #327

But I haven't found the magical combination of steps necessary to reproduce the bug outside of cordova. @adamdbradley do you have a script to create a targetless event that I can add to our tests without setting up cordova on our CI?

This also doesn't address Zones possibly not properly including or wrapping Cordova's custom events - it just makes sure that it won't outright fail.

@adamdbradley
Copy link
Author

adamdbradley commented Apr 18, 2016

@juliemr I dug through cordova and it looks like the pause event ultimately calls fireDocumentEvent

Next, it passes the created evt to documentEventHandlers[type].fire(evt)

Which is cordova's Channel.prototype.fire

The fireArgs variable from within Channel.prototype.fire has the null target:
image

Channel.prototype.fire then creates and runs each function in the toCall array, use the event with the null target:
image

One of them being the callback created from within zone's patchViaCapturingAllTheEvents(), which is expecting the event to have a target.

Sorry I'm not able to provide an explanation as to why cordova is calling these events like this, but hopefully this can help document where the issues are coming from, and to help create tests. Hope that helps, thanks.

juliemr added a commit to juliemr/zone.js that referenced this issue Apr 19, 2016
@juliemr
Copy link
Member

juliemr commented Apr 19, 2016

Note that this should be fixed (with my dumb fix) in the current version, but I'm leaving this open since we still don't actually have a test to guard against it failing.

@peter-fu
Copy link

peter-fu commented May 6, 2016

The error still occurs in iOS simulator for pause event.

exeption nativeEvalAndFetch : TypeError: null is not an object (evaluating 'elt.constructor')

How about making it like this? (I have tried this code locally and there's no error for the pause event any more).

if (elt && elt.constructor) {
  source = elt.constructor['name'] + '.' + onproperty;
} else {
  source = 'unknown.' + onproperty;
}

I'm using Ionic 2 beta, this error can be reproduced in all Ionic 2 beta projects.

$ ionic info

Your system information:

Cordova CLI: 6.1.1
Gulp version:  CLI version 3.9.0
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.6-201604261740
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
ios-deploy version: 1.8.6 
ios-sim version: 5.0.6 
OS: Mac OS X El Capitan
Node Version: v4.3.2
Xcode version: Xcode 7.3.1 Build version 7D1014 

However, I didn't observe such error with the HelloWorld project created by Cordova followed by this article - http://cordova.apache.org/docs/en/latest/guide/cli/index.html. So I am not sure where the root cause of the problem locates.

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

No branches or pull requests

5 participants