Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 917435 of Running and debugging apps

  • Revision slug: Tools/WebIDE/Running_and_debugging_apps
  • Revision title: Running and debugging apps
  • Revision id: 917435
  • Created:
  • Creator: jryans
  • Is current revision? No
  • Comment Update Full DevTools link

Revision Content

Running apps

When you're ready to run the app, you need to select a runtime from the "Select Runtime" dropdown menu. If you don't have any available runtimes here, find out how to add some in Setting up runtimes.

The "play" button in the center of the WebIDE toolbar is now enabled: click it to install and run the app in the selected runtime:

Running a custom build step

New in Firefox 37.

For some use cases you need to run a custom command before pushing your app to the device. For example, you might want to satisfy JavaScript dependencies or minify CSS, or use WebIDE to develop Gaia apps or Cordova apps, both of which require a custom build step.

From Firefox 37 you can do this by including a file called "package.json" in the root of your app. This is the same file that's used to package a node.js library, so you might already have one in the root of your project. If you don't, you can create one for this purpose.

Inside package.json, WebIDE looks for a property called "webide". The table below summarises the syntax of "webide":

webide    

Object containing instructions for WebIDE.

This may contain two properties, both optional: "prepackage" and "packageDir".

  prepackage  

Specifies a command-line command for WebIDE to run before pushing the app to the runtime.

This may be a string, in which case the command is just executed as-is, or may be an object which must contain "command", and may contain any of "env", "args", and "cwd".

    command

The command to execute in the command shell.

For example: "echo".

    env

Any environment variables to set.

This is specified as an array of strings in the form "NAME=value". For example: ["NAME=world"]

    args

Any arguments to pass along with the command.

This is specified as an array of strings.

    cwd

The directory from which to run the command.

This may be absolute or relative to the current directory.

  packageDir  

The directory from which WebIDE should look for the app to push to the runtime.

Use this if you want the project in WebIDE to be the source from which to build a packaged app. The build step specified in prepackage would place the built app in an output directory, you will specify the output directory in packageDir, and WebIDE will install the app from that output directory rather than the project directory.

This property is optional, and if it's omitted WebIDE will package the app from the project root, just as if package.json was omitted.

A "package.json" to build a Gaia app:

{
  "webide": {
    "prepackage": {
      "command": "make",
      "env": ["APP=settings"],
      "cwd": "../.."
    },
    "packageDir": "../../build_stage/settings/"
  }
}

A "package.json" for working with Cordova:

{
  "webide": {
    "prepackage": "cordova prepare",
    "packageDir": "./platforms/firefoxos/www"
  }
}

From Firefox 39 onwards, WebIDE automatically detects Cordova apps, and if it decides that your app is a Cordova app, will automatically generate a "package.json" file with these contents. See Working with Cordova apps in WebIDE.

Debugging apps

To debug the app, click the "Pause" button and the Developer Tools Toolbox appears, connected to your app:

From Firefox 36 onwards, the "Pause" button is replaced with a wrench icon.

Exactly which tools you'll have available depends on the runtime, but you will at least have the basics: the Inspector, Console, JavaScript Debugger, Style Editor, Profiler and Scratchpad. Just as in a web page, any changes you make in the tools are visible immediately in the app, but are not persistent. Conversely, any changes you make in the editor pane can be saved straight back to disk, but are not visible without restarting the app.

If you're interested in the performance of your apps, there are a few ways to measure their impact on the runtime in WebIDE:

  • The Monitor panel offers a good overview of a device's performance. This can help you detect problems, e.g. a sudden, excessive increase in an app's memory usage (leak).
  • The Profiler tool gives you a way to analyze a single app's footprint in great detail. This is especially useful when investigating a known performance problem.

Unrestricted app debugging (including certified apps, main process, etc.)

You can run the debugger against the simulator, b2g desktop, or a real device.

With the Simulator, if you click on the app dropdown menu while the runtime is selected, you can see and debug not only your app but all apps running in that runtime, including certified apps:


However, when connecting to a real device we have a security policy in force:

  • On devices running Firefox OS versions up to 2.1, all installed apps on device that are not certified apps (so privileged and web / regular apps) appear in "Runtime Apps" by default.
  • On Firefox 2.1 and above, we changed this so that only apps installed via DevTools / WebIDE appear in "Runtime Apps", regardless of app type. We did this to protect potentially sensitive data that could be present in apps.

To remove this restriction:

  • The device must be running a development build of Firefox OS 1.2+
  • You must disable the DevTools restricted privileges setting.

To disable DevTools restricted privileges, connect to the runtime, and then, in the menu, go to Runtime > Runtime Info. The path then differs depending on what you are debugging against:

  • Real device
    • If it can be rooted, clicking "request higher privileges" will enable unrestricted app debugging (Firefox OS will restart). You may need to select your device again in the 'Select Runtime' drop down.
    • If it cannot be rooted, there is a developer setting available in Firefox OS 2.2 onwards called Reset and enable full DevTools — when activated this will wipe all user data (for security reasons), reset the device, and enable unrestricted priviledges on any device.
  • Simulator
    • The simulators come with unrestricted app debugging enabled by default.
  • B2G desktop
    • Manually edit the B2G desktop client preferences before connecting to enable unrestricted app debugging.

Now (or after a restart of the B2G desktop client) in WebIDE you should see all the apps on the device.

Revision Source

<h2 id="Running_apps">Running apps</h2>

<p>When you're ready to run the app, you need to <a href="/en-US/docs/Tools/WebIDE/Setting_up_runtimes#Selecting_a_runtime">select a runtime from the "Select Runtime" dropdown menu</a>. If you don't have any available runtimes here, find out how to add some in <a href="/en-US/docs/Tools/WebIDE/Setting_up_runtimes">Setting up runtimes</a>.</p>

<p>The "play" button in the center of the WebIDE toolbar is now enabled: click it to install and run the app in the selected runtime:</p>

<p><img alt="" src="https://mdn.mozillademos.org/files/8065/webide-running.png" style="display:block; height:718px; margin-left:auto; margin-right:auto; width:1314px" /></p>

<h3 id="Running_a_custom_build_step">Running a custom build step</h3>

<div class="geckoVersionNote">
<p>New in Firefox 37.</p>
</div>

<p>For some use cases you need to run a custom command before pushing your app to the device. For example, you might want to satisfy JavaScript dependencies or minify CSS, or use WebIDE to develop Gaia apps or Cordova apps, both of which require a custom build step.</p>

<p>From Firefox 37 you can do this by including a file called "package.json" in the root of your app. This is the same file that's used to <a href="https://docs.npmjs.com/files/package.json">package a node.js library</a>, so you might already have one in the root of your project. If you don't, you can create one for this purpose.</p>

<p>Inside package.json, WebIDE looks for a property called "webide". The table below summarises the syntax of "webide":</p>

<table class="standard-table">
 <tbody>
  <tr>
   <td style="width: 10%;"><code>webide</code></td>
   <td style="width: 10%;">&nbsp;</td>
   <td style="width: 10%;">&nbsp;</td>
   <td style="width: 70%;">
    <p>Object containing instructions for WebIDE.</p>

    <p>This may contain two properties, both optional: "<code>prepackage</code>" and "<code>packageDir</code>".</p>
   </td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td><code>prepackage</code></td>
   <td>&nbsp;</td>
   <td>
    <p>Specifies a command-line command for WebIDE to run before pushing the app to the runtime.</p>

    <p>This may be a string, in which case the command is just executed as-is, or may be an object which must contain "<code>command</code>", and may contain any of "<code>env</code>", "<code>args</code>", and "<code>cwd</code>".</p>
   </td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><code>command</code></td>
   <td>
    <p>The command to execute in the command shell.</p>

    <p>For example: "<code>echo</code>".</p>
   </td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><code>env</code></td>
   <td>
    <p>Any environment variables to set.</p>

    <p>This is specified as an array of strings in the form "NAME=value". For example: <code>["NAME=world"]</code></p>
   </td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><code>args</code></td>
   <td>
    <p>Any arguments to pass along with the command.</p>

    <p>This is specified as an array of strings.</p>
   </td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><code>cwd</code></td>
   <td>
    <p>The directory from which to run the command.</p>

    <p>This may be absolute or relative to the current directory.</p>
   </td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td><code>packageDir</code></td>
   <td>&nbsp;</td>
   <td>
    <p>The directory from which WebIDE should look for the app to push to the runtime.</p>

    <p>Use this if you want the project in WebIDE to be the source from which to build a packaged app. The build step specified in <code>prepackage</code> would place the built app in an output directory, you will specify the output directory in <code>packageDir</code>, and WebIDE will install the app from that output directory rather than the project directory.</p>

    <p>This property is optional, and if it's omitted WebIDE will package the app from the project root, just as if package.json was omitted.</p>
   </td>
  </tr>
 </tbody>
</table>

<p>A "package.json" to build a Gaia app:</p>

<pre class="brush: json">
{
  "webide": {
    "prepackage": {
      "command": "make",
      "env": ["APP=settings"],
      "cwd": "../.."
    },
    "packageDir": "../../build_stage/settings/"
  }
}</pre>

<p>A "package.json" for working with Cordova:</p>

<pre class="brush: json">
{
  "webide": {
    "prepackage": "cordova prepare",
    "packageDir": "./platforms/firefoxos/www"
  }
}</pre>

<div class="note">
<p>From Firefox 39 onwards, WebIDE automatically detects Cordova apps, and if it decides that your app is a Cordova app, will automatically generate a "package.json" file with these contents. See <a href="/en-US/docs/Tools/WebIDE/Working_with_Cordova_apps_in_WebIDE">Working with Cordova apps in WebIDE</a>.</p>
</div>

<h2 id="Debugging_apps">Debugging apps</h2>

<p>To debug the app, click the "Pause" button and the Developer Tools <a href="/en-US/docs/Tools/Tools_Toolbox">Toolbox</a> appears, connected to your app:</p>

<p><img alt="" src="https://mdn.mozillademos.org/files/8067/webide-debugging.png" style="display:block; height:688px; margin-left:auto; margin-right:auto; width:1310px" /></p>

<div class="geckoVersionNote">
<p>From Firefox 36 onwards, the "Pause" button is replaced with a wrench icon.</p>
</div>

<p>Exactly which tools you'll have available depends on the runtime, but you will at least have the basics: the <a href="/en-US/docs/Tools/Page_Inspector">Inspector</a>, <a href="/en-US/docs/Tools/Web_Console">Console</a>, <a href="/en-US/docs/Tools/Debugger">JavaScript Debugger</a>, <a href="/en-US/docs/Tools/Style_Editor">Style Editor</a>, <a href="/en-US/docs/Tools/Profiler">Profiler</a> and <a href="/en-US/docs/Tools/Scratchpad">Scratchpad</a>. Just as in a web page, any changes you make in the tools are visible immediately in the app, but are not persistent. Conversely, any changes you make in the editor pane can be saved straight back to disk, but are not visible without restarting the app.</p>

<p>If you're interested in the performance of your apps, there are a few ways to measure their impact on the runtime in WebIDE:</p>

<ul>
 <li>The <a href="/docs/Tools/WebIDE/Monitor">Monitor</a> panel offers a good overview of a device's performance. This can help you detect problems, e.g. a sudden, excessive increase in an app's memory usage (leak).</li>
 <li>The <a href="/docs/Tools/Profiler">Profiler</a> tool gives you a way to analyze a single app's footprint in great detail. This is especially useful when investigating a known performance problem.</li>
</ul>

<h3 id="Unrestricted_app_debugging_(including_certified_apps_main_process_etc.)">Unrestricted app debugging (including certified apps, main process, etc.)</h3>

<p>You can run the debugger against the simulator, b2g desktop, or a real device.</p>

<p>With the Simulator, if you click on the app dropdown menu while the runtime is selected, you can see and debug not only your app but all apps running in that runtime, including <a href="/en-US/Marketplace/Options/Packaged_apps#Certified_app">certified apps</a>:</p>

<p><img alt="" src="https://mdn.mozillademos.org/files/8069/webide-debugging-builtin.png" style="display:block; height:681px; margin-left:auto; margin-right:auto; width:1302px" /></p>

<p><br />
 However, when connecting to a real device we have a security policy in force:</p>

<ul>
 <li>On devices running Firefox OS versions up to 2.1, all installed apps on device that are <strong>not</strong> certified apps (so privileged and web / regular apps) appear in "Runtime Apps" by default.</li>
 <li>On Firefox 2.1 and above, we changed this so that only apps installed via DevTools / WebIDE appear in "Runtime Apps", regardless of app type. We did this to protect potentially sensitive data that could be present in apps.</li>
</ul>

<p>To remove this restriction:</p>

<ul>
 <li>The device must be running a development build of Firefox OS 1.2+</li>
 <li>You must disable the <code>DevTools restricted privileges</code> setting.</li>
</ul>

<p>To disable <code>DevTools restricted privileges</code>, connect to the runtime, and then, in the menu, go to <code>Runtime &gt; Runtime Info</code>. The path then differs depending on what you are debugging against:</p>

<ul>
 <li>Real device
  <ul>
   <li>If it can be rooted, clicking <code>"request higher privileges"</code> will enable unrestricted app debugging (Firefox OS will restart). You may need to select your device again in the 'Select Runtime' drop down.</li>
   <li>If it cannot be rooted, there is a developer setting available in Firefox OS 2.2 onwards called <a href="https://developer.mozilla.org/Firefox_OS/Debugging/Developer_settings#Full_DevTools">Reset and enable full DevTools</a> — when activated this will wipe all user data (for security reasons), reset the device, and enable unrestricted priviledges on <em>any</em> device.</li>
  </ul>
 </li>
 <li>Simulator
  <ul>
   <li>The simulators come with unrestricted app debugging enabled by default.</li>
  </ul>
 </li>
 <li>B2G desktop
  <ul>
   <li>Manually edit the B2G desktop client <a href="https://developer.mozilla.org/en-US/Firefox_OS/Using_the_App_Manager#Using_the_B2G_desktop_client">preferences</a> before connecting to enable unrestricted app debugging.</li>
  </ul>
 </li>
</ul>

<p>Now (or after a restart of the B2G desktop client) in WebIDE you should see all the apps on the device.</p>
Revert to this revision