-
Notifications
You must be signed in to change notification settings - Fork 408
#445 fix causes uncaught promise rejection in chrome #446
Comments
Actually, is this a bug with chrome devtools? The exception does appear to be being caught - but I don't have "Pause On Caught Exceptions" ticked, as per the screenshot. |
Having this same problem on Chrome |
Having the same problem, Chrome 53.0.2785.116 m (64-bit). My angular 2 page works fine in Firefox but gets this error in Chrome: |
It looks like chrome may have fixed their "bug"?? where they allowed an empty fetch call, because that did work for me before without hitting a promise rejection breakpoint while in debug mode before. I'm not sure which version of chrome I was on, but I am currently on Version 53.0.2785.116 m (64-bit). My previous fix using an empty string still seems to work in both Edge and IE.
|
We're having this problem, too, and I can confirm the wizarrc's fix solves the issue. |
We're seeing this problem in only Edge 38.14393.0.0, where it crashes the script load. |
The problem with @wizarrc's solution - #446 (comment) - is that it introduces a side-effect - a GET request is made to the current page: |
@petewalker I think the point of the fetch was to confirm functionality. I would be interested in a reliable way to test functionality that did not waste undue resources. I would imagine a local resource would be needed for each browser. Good catch. I want to add I didn't mean to suggest that this was a permanent solution, but rather a quick fix/workaround for those waiting for an update like myself. Nothing is more annoying than trying to test your project and it stops working after trying a different browser/updating npm packages.
@petewalker It does look like chrome is in fact pausing on any error now without the checkbox selected when debugging tools are open that it used to just send to the console (very annoying). It's possible that it was rejecting the promise without throwing an error unlike the Edge Browser all this time in the past and no one ever noticed. The Edge Browser will not even attempt to fetch with a null parameter and instead immediately throw whereas Chrome will instead return a rejected promise. |
confirming on angular 2.0.0, zone-js 0.6.12, and chrome 53.0.2785.143 |
same problem confirmed on angular 2.0.1, zone-js 0.6.12, and chrome 53.0.2785.116 |
I don't see this causing issues if 'Pause on Uncaught Exceptions' is unchecked, but I do see the pause if it is checked. Chrome 53.0.2785.143. for those that are using an older version of zone.js, please try updating to the latest. |
It's occurring for me whether "Pause on Uncaught Exceptions" is checked or not. Chrome 53.0.2785.143, zone.js 0.6.25. It appears that the Chrome implementation is throwing the error in a way that can't be caught in userland. Running the following in devtools with "Pause on exceptions" activated:
All result (for me) with the console pausing with:
|
Is there any update on this? It is still fantastically annoying to have to press continue every time I load an app with dev tools open... |
@teone - please see my comment above: #446 (comment) |
Using same setup as teone I can confirm that issue still exists. Very annoying. |
Yes, same issue for me too, very annoying |
Having look at this again, I'm pretty sure the call to |
@petewalker Do you think it's possible to lazy patch it on first use of fetch? If that were possible, as soon as a fetch is called, do the patch and make the legitimate live fetch call. Not sure how that would work though. |
@wizarrc Potentially. The only simple way I can think to do that would be to create a wrapper method for let NativeFetch = global['fetch'];
global['fetch'] = function(url, init) {
return NativeFetch(url, init).then(
// ...
);
} I'm not that acquainted with the inner workings of Zone, so I'm not sure what implications something like this would have are. I suspect that by the time the promise is run it's already too late? The really interesting thing is that the patching of the fetched Having had a quick play in Edge and Firefox, they both also seem to return a native promise - so I'd be curious to learn the circumstances in which this code does fire. Perhaps polyfills? Or where someone has previously overridden the global Promise? Or are we looking at non-browser implementations of the Fetch API? The change was introduced here: 5f1ea90 Unfortunately it's not attached to a particular issue, so I'm not sure what its history is... |
@petewalker I had this problem previously before TypeScript 2.1 when I needed async await support to compile down to es5. In order to unlock this capability, I had to enable babel in the pipeline, which had to be loaded before zone.js. The pipeline was TypeScript (target es6) -> Babel (target es5) -> javascript. I believe the first thing that babel library did was override the Promise implementation (thus why I first received this weird error). To workaround this error during development I modified the zone.js during dev with an environment variable and set the fetch with empty string value. I since was able to remove that (babel and it's polyfill) altogether since TypeScript 2.1 came out and I am able to independently add polyfills when I need browser support and have my much needed async await support. |
So what exactly should I do for fix that exception? |
If I understand correctly, the call to fetch() is done to get a hold of its result promise and patch the constructor that created it if needed (in case fetch() is some polyfill using its own promise implementation). Fixes the issue for me (...which annoyed me enough to motivate me to do a little digging). |
Yep, I believe your understanding is correct. It'd require some testing. I've tried it here in Chrome, Firefox and Safari, and it seems to be consistent. It's a bit hacky - but until Chrome is changed upstream (if ever), I can't see another way around it. Your fix isn't quite right, though - you're missing a // Are we dealing with a non-native fetch-implementation?
// If so, also patch its result promise constructor.
var fetch = global['fetch'];
if (typeof fetch !== 'undefined' &&
fetch.toString().indexOf('[native code]') == -1) {
// ...
} |
Oh, darn typeof, sorry for that stupid mistake. I'm creating a new change: MichaelBuerge@8e20690
I agree about it being a bit hacky. However, I do consider patching native constructors to be somewhat hacky to begin with, as it often leads to unexpected problems down the road. As evidenced by this issue, I might add. Regarding testing: I just tested it manually in lots browsers (Chrome, FF, IE9/10/11, Edge) and didn't observe any problems. |
Progress report: Details: See below for the full output from FF and Chrome. The important bits are (from FF): Conclusion: It doesn't work as I hoped and expected. FF: Chrome: |
I think to ignore the error, just unchecked the 'pause on uncaught exception' which described here, |
@JiaLiPassion Yes, that's true - but this code shouldn't be throwing an exception at all. |
@petewalker, yes, current situation is
Now it seems chrome dev tool will also pause on rejected promise. |
Took another look at this and found a solution. Some noteworthy things I came across investigating this:
With all this patching on it was quite tricky figuring out what actually is going on. |
See your PR was merged, @MichaelBuerge 👍 Looking forward to seeing this in a release..! |
I have no problem with the test Plunker but do have problem within vscode. I am using code 1.9.1, zonejs 0.7.6, and chrome 56.0.2924.87. It seemed the problem is solved but I need to know what to do with my code. |
The fix in #445 causes an uncaught promise rejection in Chrome.
Chrome Version: 53.0.2785.116 (64-bit)
Reproduction:
Expected:
Page refreshes without error
Actual:
Page refresh is caught by uncaught rejection:
The text was updated successfully, but these errors were encountered: