Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Debugging network requests in the Moodle App: Difference between revisions

From MoodleDocs
(Clean up)
Line 3: Line 3:
== Introduction ==
== Introduction ==


This guide will help you find and report problems with the Moodle Mobile app on your site.
This guide will help you find and report problems with the Moodle App on your site.


It is especially useful for the following problems:
It is especially useful for the following problems:
* Unable to log in on your site
 
* Unable to log in on your site.
* When you receive one of the following error messages in the app:
* When you receive one of the following error messages in the app:
** Can not find data record in database table external_functions
** "Can not find data record in database table external_functions".
** Invalid response value detected
** "Invalid response value detected".
** Cannot get course contents
** "Cannot get course contents".
 
== Requirements ==
* Moodle 3.1 onwards (your site needs at least this version)
* Google Chrome/Chromium browser
[[{{ns:file}}:moodlemobile_enabledebug.png|thumb|300px]]


== Enabling debugging on your Moodle site ==
== Enabling debugging on your Moodle site ==


# Go to Debugging in the Site administration
# Go to Debugging in the Site administration.
# For "Debug messages" select 'DEVELOPER'
# For "Debug messages" select 'DEVELOPER'.
# Tick "Display debug messages"
# Tick "Display debug messages".
# Click the 'Save changes' button.
# Click the 'Save changes' button.


Note: Remember to disable debugging again once you have finished debugging your problem.


== Enabling debugging on the mobile app ==
Remember to disable debugging again once you have finished debugging your problem.
 
== Enabling debugging on the Moodle App ==
 
# Go to the More tab.
# Go to Settings > General.
# Enable "Display debug messages".


# Go to the More tab
# Go to Settings > General
# Enable "Display debug messages"


Note: Remember to disable debugging again once you have finished debugging your problem.
Remember to disable debugging again once you have finished debugging your problem.


== First try ==
== First attempts ==


At this point, you may not need fo go further on this guide.
At this point, you may not need to go further on this guide.


Log-out and log-in again into your site and try to reproduce the error, hopefully, with Moodle and app debugging enabled you will see an explanatory message of what is happening.
Log out and log in again into your site and try to reproduce the error. Hopefully, with Moodle and app debugging enabled you will see an explanatory message of what is happening.


If you are unable to find a solution, contact a [https://moodle.com/partners/ Moodle Partner] or post in the [https://moodle.org/mod/forum/view.php?id=7798 Moodle for mobile forum] on moodle.org for non-guaranteed community support.
If you are unable to find a solution, contact a [https://moodle.com/partners/ Moodle Partner] or post in the [https://moodle.org/mod/forum/view.php?id=7798 Moodle for mobile forum] on moodle.org for non-guaranteed community support.
Line 44: Line 42:
== Setting up the debugging tool ==
== Setting up the debugging tool ==


=== Chrome or Chromium ===
=== Using a Browser ===


[[{{ns:file}}:moodlemobile_chrome_inspect_network.png|thumb|300px]]
In your [[Using the Moodle App in a browser|Chromium-based browser]], you can access your site using the hosted versions of the app in [https:master.apps.moodledemo.net master.apps.moodledemo.net] (the latest stable version) and [https://integration.apps.moodledemo.net integration.apps.moodledemo.net].


Another option is to use Google Chrome or Google Chromium to debug this. If you already have the Moodle Desktop app you can skip this section.
Once you're using your site, you can open the [https://developer.chrome.com/docs/devtools/network/ Network panel] of the developer tools and inspect requests. If you're only interested in web service requests, [https://developer.chrome.com/docs/devtools/network/#filter you can filter] writing <code>.php</code> in the filter input.


Debugging the mobile app is not so easy, so we have provided an online web version of the app that can be easily debugged using the Chrome browser.
=== Using a mobile device or emulator ===


# Open your Chrome browser and go to https://integration.apps.moodledemo.net/
If you are using a native device, keep in mind that some requests are not executed through the webview and you won't be able to see them in the network inspector of your developer tools. Instead, you'll have to use native tools the debug the requests.
# Open your browser options (icon at the top-right of your browser window), then go to More tools -> Developer tools
# Dock the new panels on the right side (in the new panel top-right options choose “Dock to the right” icon)
# Click the Network tab (at the top-center)
# Enable the filter (filter shape icon) so it changes to colour red
# In the new text field displayed when enabling the filter write <syntaxhighlight lang="php">.php</syntaxhighlight>


Now you are ready to debug all the web services requests sent to your Moodle site by the mobile app.
For example, in Android you can use [https://developer.android.com/studio/profile/network-profiler the Network Profiler].


== Debugging a web service (WS) error ==
=== General strategy ===


[[{{ns:file}}:moodlemobile_chrome_debug_ws_error.png|thumb|300px]]
Here's how to debug web service errors:


# Connect to your site and browse to the functionality displaying an error
# Ignore requests that don’t start with <code>token.php</code> or <code>server.php</code>.
# In the right panel you will see a list of requests made by the app to your Moodle site (token.php server.php server.php etc..)
# Once you have selected a request you want to inspect, open the "Response" tab and check if you see an error.
# Click on each one of them (starting with the last one in the list) but skip those that don’t start with token.php or server.php
# If you don't understand how to fix the error, you can search in [[:en:Moodle Mobile FAQ|Moodle Mobile FAQ]] to check if there is a known solution.
# In the new sub-window open select the “Response” tab and check if you see an error
# Copy the error then go to the [[:en:Moodle Mobile FAQ|Moodle Mobile FAQ]] in the user docs to check if there is a known solution for it
# If you are unable to find a solution, contact a [https://moodle.com/partners/ Moodle Partner] or post in the [https://moodle.org/mod/forum/view.php?id=7798 Moodle for mobile forum] on moodle.org for non-guaranteed community support.
# If you are unable to find a solution, contact a [https://moodle.com/partners/ Moodle Partner] or post in the [https://moodle.org/mod/forum/view.php?id=7798 Moodle for mobile forum] on moodle.org for non-guaranteed community support.


== Troubleshooting ==
== Troubleshooting ==


'''How to log-in into a site configured to use browser or embedded authentication'''
=== How to log into a site configured to use browser or embedded authentication ===
 
You can execute the following in the js console:
 
window.handleOpenURL("moodlemobile://URL?token=WSTOKEN");


You can also launch a normal authentication process (allowing the authentication popup) and capture in the Network tab the redirect to moodlemobile://... created by the admin/tool/mobile/launch.php script and then execute in the console:
You can execute the following in the JavaScript console:


  window.handleOpenURL("moodlemobile://token=ABCxNGUxMD........=");
<syntaxhighlight lang="javascript">
window.handleOpenURL("moodlemobile://URL?token=WSTOKEN");
</syntaxhighlight>


== See also ==
You can also launch a normal authentication process (allowing the authentication popup) and capture the redirect to <code>moodlemobile://...</code> created by the <code>admin/tool/mobile/launch.php</code> script and then execute the following in the console:


* [[Moodle Mobile development using Chrome or Chromium]]
<syntaxhighlight lang="javascript">
window.handleOpenURL("moodlemobile://token=ABCxNGUxMD........=");
</syntaxhighlight>

Revision as of 11:56, 15 September 2021


Introduction

This guide will help you find and report problems with the Moodle App on your site.

It is especially useful for the following problems:

  • Unable to log in on your site.
  • When you receive one of the following error messages in the app:
    • "Can not find data record in database table external_functions".
    • "Invalid response value detected".
    • "Cannot get course contents".

Enabling debugging on your Moodle site

  1. Go to Debugging in the Site administration.
  2. For "Debug messages" select 'DEVELOPER'.
  3. Tick "Display debug messages".
  4. Click the 'Save changes' button.


Remember to disable debugging again once you have finished debugging your problem.

Enabling debugging on the Moodle App

  1. Go to the More tab.
  2. Go to Settings > General.
  3. Enable "Display debug messages".


Remember to disable debugging again once you have finished debugging your problem.

First attempts

At this point, you may not need to go further on this guide.

Log out and log in again into your site and try to reproduce the error. Hopefully, with Moodle and app debugging enabled you will see an explanatory message of what is happening.

If you are unable to find a solution, contact a Moodle Partner or post in the Moodle for mobile forum on moodle.org for non-guaranteed community support.

Setting up the debugging tool

Using a Browser

In your Chromium-based browser, you can access your site using the hosted versions of the app in [https:master.apps.moodledemo.net master.apps.moodledemo.net] (the latest stable version) and integration.apps.moodledemo.net.

Once you're using your site, you can open the Network panel of the developer tools and inspect requests. If you're only interested in web service requests, you can filter writing .php in the filter input.

Using a mobile device or emulator

If you are using a native device, keep in mind that some requests are not executed through the webview and you won't be able to see them in the network inspector of your developer tools. Instead, you'll have to use native tools the debug the requests.

For example, in Android you can use the Network Profiler.

General strategy

Here's how to debug web service errors:

  1. Ignore requests that don’t start with token.php or server.php.
  2. Once you have selected a request you want to inspect, open the "Response" tab and check if you see an error.
  3. If you don't understand how to fix the error, you can search in Moodle Mobile FAQ to check if there is a known solution.
  4. If you are unable to find a solution, contact a Moodle Partner or post in the Moodle for mobile forum on moodle.org for non-guaranteed community support.

Troubleshooting

How to log into a site configured to use browser or embedded authentication

You can execute the following in the JavaScript console:

window.handleOpenURL("moodlemobile://URL?token=WSTOKEN");

You can also launch a normal authentication process (allowing the authentication popup) and capture the redirect to moodlemobile://... created by the admin/tool/mobile/launch.php script and then execute the following in the console:

window.handleOpenURL("moodlemobile://token=ABCxNGUxMD........=");