How to watch console.logs in ionic emulator?

前端 未结 6 1009
别那么骄傲
别那么骄傲 2021-02-01 14:33

I\'m building an app using the Ionic framework, which I\'ve done in the browser until now. Because I now want to use the cordovaOauth plugin I need to use the emulator. The prob

相关标签:
6条回答
  • 2021-02-01 14:40

    On Ionic 3, you can do this by

    ionic cordova run android --emulator -l -c
    

    Replace android with ios depending on your requirements. More information here: https://ionicframework.com/docs/cli/cordova/run/

    0 讨论(0)
  • 2021-02-01 14:41

    Just enable the console logs in the emulator. Here my example:

    > ionic emulate ios --livereload
    
      Setup Live Reload
      Running dev server: http://localhost:8100
      Adding in default Ionic hooks
      Running live reload server: http://localhost:35729
      Watching : [ 'www/**/*', '!www/lib/**/*' ]
      Ionic server commands, enter:
        restart or r to restart the client app from the root
        goto or g and a url to have the app navigate to the given url
        consolelogs or c to enable/disable console log output
        serverlogs or s to enable/disable server log output
        quit or q to shutdown the server and exit
    

    Type consolelogs in the command line and hit enter.

      consolelogs
    
      Console log output: enabled
      Loading: /?restart=382451
      ionic $ 0     498458   log      Hi there! This is from console.log
    
    0 讨论(0)
  • 2021-02-01 14:49

    run ionic emulate ios -l -c

    This will open the emulator with livereload feature, and you'll see all the console logs in the terminal. To turn the console logs off (or on) just write consolelogs or just c in the terminal while the ionic server is running

    Another very convenient way to debug your app when using iOS emulator/device is using the Safari developer tools

    When the app runs - enter Safari and choose "Develop > iOS Simulator > your page"

    If you work with a real device you'll see the device's name instead of "iOS Simulator"

    If you don't see the "Develop" menu in safari - enter Safari's preferences and enable it from the "advanced" tab

    0 讨论(0)
  • 2021-02-01 14:58
    1. If you wan't to watch console logs in emulator / simulator use

      ionic emulate -l -c <PLATFORM>

    2. If you wan't to watch console logs when testing in device you can launch this command :

      ionic run -l -c <PLATFORM>

    -c = --consolelogs : Print app console logs to Ionic CLI (livereload req.)

    -l = --livereload : Live reload app dev files from the device

    May help someone !

    0 讨论(0)
  • 2021-02-01 15:00

    If you are testing your web app with a device running Android 4.4 or higher, you can remotely debug your web pages in WebView with Chrome Developer Tools. Just open chrome://inspect on your desktop with the phone in USB Debugging mode connected.

    0 讨论(0)
  • 2021-02-01 15:01

    There are a few ways to debug your ionic app.

    • In the browser you can catch the errors in the console.
    • If you are emulating your app on a simulator or a mobile device you can install the cordova plugin that displays js errors in the xcode console. So you can emulate your device and catch errors on xcode.

    Here is how you add the plugin:

    cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git

    Hope this helps! It came in very handy for me while I was debugging GeoFire errors and testing the cordova camera and geolocation api.

    0 讨论(0)
提交回复
热议问题