phonegap / phonegap-app-developer

PhoneGap Developer App
app.phonegap.com
Apache License 2.0
2k stars 2.51k forks source link

[discuss] JavaScript errors can halt update/refresh logic #474

Open mwbrooks opened 7 years ago

mwbrooks commented 7 years ago

Original issue

https://github.com/phonegap/phonegap-app-developer/issues/291

Overview

When an error occurs while the page is loading, it can cause the update/refresh logic to fail to initialize or halt entirely.

Steps to Reproduce

Can someone please provide a small example that reproduces this error.

Discuss

Can we prevent this from occurring? If not, can we detect that the Mobile app is not refreshing from the client-side (CLI) or native-side (mobile app)?

tylermakin commented 7 years ago

From #291:

@mwbrooks I do not recall the specific bug that caused my script to stop but anything that prevents a page from loading properly should do the trick.

A simple bug that should cause this issue is calling an undefined variable:

console.log('This will appear on console');
var b = a;
console.log('This will not appear in console');

Adding this to your JavaScript should throw an error and stop any further JS from loading, which seems to be what is causing the PhoneGap Developer app from refreshing.

surajpindoria commented 7 years ago

Is this something that will get fixed once we add phonegap-plugin-developer-mode? @timkim

timkim commented 7 years ago

So far the best way to debug javascript errors is through:

  // err: error message
  // fileName: which file error occurs in
  // lineNumber: what line error occurs on
  window.onerror = function (err, fileName, lineNumber) {
    // alert or console.log a message
    alert(fileName, 'Line:', lineNumber, 'Error:', e.message);
  };

However, the user themselves have to put that in their app in order to see if an error fires or not. It might be worthwhile having that snippet within the developer mode plugin. Maybe have our own error reporter callback?

There are plans for using multi-webviews in the developer app, but that's a feature that will be coming sometime later this year. However, even using that doesn't quite solve broken js, but it will the user to easily go back to the main input screen.