mozilla
Your Search Results

    WebIDE

    WebIDE is available from Firefox 34 onwards.

    WebIDE is the replacement for the App Manager. Like the App Manager, it enables you to run and debug Firefox OS apps using the Firefox OS Simulator or a real Firefox OS device.

    However, it also provides an editing environment for you to create and develop Firefox OS apps, including a tree view of all the files in your app with the ability to edit and save them, and two app templates to help you get started.

    Finally, WebIDE enables you to connect the Firefox Developer Tools to a number of other browsers, including Firefox for Android, Chrome on Android, and Safari on iOS. See the Remote Debugging page for instructions on how to connect to a specific browser.

    With WebIDE, you first set up one or more runtimes. A runtime is an environment in which you'll run and debug the app. A runtime could be a Firefox OS device connected to the desktop over USB, or it could be a Firefox OS Simulator installed on the desktop itself.

    Next, you create an app, or open an existing app. If you're creating a new app you start with a template that includes the directory structure and the minimum boilerplate you need to get started, or a more complete template that shows how to use a privileged API. WebIDE shows your app's files in a tree, and you can edit and save them using a built-in source editor. Of course, you don't have to use the built-in editor: you can develop your app entirely outside WebIDE, and only use it for debugging.

    Finally, you can install the app in one of the runtimes and run it. You can then open the usual suite of developer tools - the Inspector, Console, JavaScript Debugger and so on - to examine and modify the running app.

    System requirements

    To develop and debug apps using WebIDE, all you need is Firefox version 33 or later. To test on a real Firefox OS device, you need a device running Firefox OS 1.2 or later, and a USB cable.

    You can only use WebIDE for Firefox OS if you're targeting Firefox OS 1.2 or later.

    Opening WebIDE

    There are three ways to open WebIDE:

    • In the Web Developer menu, click on the "WebIDE" entry and WebIDE opens.
    • Use the keybinding Shift-F8.
    • A dedicated icon in the Firefox toolbar. This is always present if you're using Firefox Developer Edition, and with any Firefox from version 36 onwards it appears after you've opened the WebIDE once:

    Here's what the WebIDE looks like:The dropdown on the left labeled "Open App" lets you open existing apps or create new ones. The dropdown on the right labeled "Select Runtime" lets you select a runtime or set up a new runtime.

    The buttons in the middle run, stop, and debug the app: they are only enabled when you have opened an app and selected a runtime.

    From Firefox 36, you can change the font size throughout WebIDE using the standard keyboard shortcuts (use Command instead of Control on OS X):

    • Ctrl + increases font size
    • Ctrl - decreases font size
    • Ctrl 0 resets the font size to the default

    Setting up runtimes

    Under the "Select Runtime" dropdown, runtimes are grouped into three types:

    The first time you click the dropdown, you might not see any runtimes here:

    The rest of this section describes how you can add some runtimes.

    Connecting a Firefox OS device

    Before you can connect a Firefox OS device, there's some setup you have to go through:

    • Check your Firefox OS version: Make sure your device is running Firefox OS 1.2/Boot2Gecko 1.2 or higher. To check the version, go to the Settings app on the device, then Device Information > Software. If you don't have a high enough version, find your device in the developer phone guide and follow the instructions for upgrading.
    • Enable remote debugging: In the Settings app on the device, go to Device information > More information > Developer.
      • Firefox OS 1.3 and earlier: "Remote Debugging" is just a simple checkbox. Check it.
      • Firefox OS 1.4 and later: "Remote Debugging" asks you to enable for just ADB, or for ADB and DevTools. Select "ADB and DevTools".
    • Disable Screen lock on your device: In the Settings app on the device, go to Screen Lock and uncheck the Lock Screen checkbox. This is required because when the screen gets locked, the phone connection gets lost, meaning it is no longer available for debugging.
    • If you want unrestricted debugging privileges, including certified apps, built-in apps, and apps already installed on a real device: See the section on Unrestricted app debugging (including certified apps, main process, etc.).

    Linux only:

    • Add a udev rules file, as documented in step 3 of this guide to setting up an Android device. The idVendor attribute to use for the Geeksphone is "05c6", and this page lists other idVendor values.

    Windows only:

    If there are any other Android devices connected to your computer, disconnect them. Now connect the device to the computer using USB. You should see the device appear under "USB DEVICES":

    If you don't see your device, see the Troubleshooting page.

    Connecting to Firefox for Android

    From Firefox 36 onwards Android devices connected over USB and running Firefox for Android appear as a runtime under "USB devices". See the article on connecting to Firefox for Android from WebIDE.

    Before Firefox 36, you can connect to Firefox for Android without using WebIDE at all, or can use WebIDE by setting up a custom remote runtime.

    Adding a Simulator

    The Firefox OS Simulator is a version of the higher layers of Firefox OS that simulates a Firefox OS device, but runs on the desktop. It runs in a window the same size as a Firefox OS device, includes the Firefox OS user interface and built-in apps, and simulates many of the Firefox OS device APIs.

    This means that in many cases, you don't need a real device to test and debug your app.

    The Simulator doesn't ship inside Firefox but as a Firefox add-on. If you click "Install Simulator" in the Runtimes dropdown menu, you will go to a page from which you can install Simulators for various versions of Firefox OS.

    You can install as many as you like. Be patient, though: the Simulator may take a few minutes to download. Once you've installed some Simulators you can close this "Extra Components" window, and the Simulators you've installed appear as options in the Runtimes dropdown menu:

    To learn more about the Simulator, see its documentation page.

    Other runtimes

    Remote runtime

    With a remote runtime you can use an arbitrary hostname and port to connect to the remote device.

    Under the hood, Firefox OS devices and Android devices connect to the desktop using a program called the Android Debug Bridge, or ADB. By default, WebIDE uses an add-on called the ADB Helper: this simplifies the process for you by installing ADB and setting up port forwarding so the Firefox desktop tools can exchange messages with the device.

    This is convenient in most cases, but sometimes you might want to use ADB outside of WebIDE: for example, you might be running ADB directly from the command line. In that case you'll connect to the device by specifying a host and port using the adb forward command (example: adb forward tcp:6000 localfilesystem:/data/local/debugger-socket).

    If you then want to use WebIDE to connect as well, you should disable the ADB Helper add-on and connect WebIDE using the Custom runtime option, entering the host and port that you passed to adb forward (example: localhost:6000).

    Also, before Firefox 36, the ADB Helper does not yet support connecting to Firefox for Android, so if you want to connect WebIDE to Firefox for Android, you'll need to set up your own port forwarding and use a custom runtime. See more about connecting to Firefox for Android using ADB prior to Firefox 36.

    Valence-enabled runtimes

    If you have the Valence add-on installed, you'll see three additional runtimes:

    • Chrome on Android
    • Safari on iOS
    • Chrome Desktop

    For instructions on how to connect to these runtimes, see the relevant entry in the Remote Debugging page.

    Selecting a runtime

    Once you've set up a runtime you can select it using the "Select Runtime" menu.

    • If you select a Simulator, WebIDE launches the Simulator.
    • If you select a Firefox OS device WebIDE connects to the device. On the device a dialog will ask you to confirm that you wish to connect: press "OK".

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

    Runtime menu items

    When a runtime is selected, the Runtimes dropdown menu has up to five extra items:

    Runtime Info
    Information on the current runtime
    Permissions Table
    A table summarising app permissions for the current runtime, indicating, for each API and each app type, whether access is allowed (✓), denied (✗), or whether the user is prompted (!)
    Device Preferences
    A table listing, and letting you edit, the preferences that are made available in the runtime via the Preferences service. These are platform-level configuration values exposing the same set of data as Firefox's about:config (but for the device). Because these preferences are highly security-sensitive, you need to disable the DevTools restricted privileges setting before you can modify them.
    Device Settings (new in Firefox 38/Firefox OS 3)
    A table listing, and letting you edit, the settings that can be controlled in the Firefox OS Settings app. Most things on the device which have a UI control to change (volume, alarm, etc.) are found in Device Settings. Because these settings are less sensitive than the device preferences, you can modify them without removing the restricted privileges setting. However, since this feature is new in Gecko 38 you need the WebIDE in Firefox 38 and a nightly build of Firefox OS or the Simulator.
    Screenshot
    A command to take a screenshot from the runtime.

     

    Creating and opening apps

    Under the "Open App" menu you get three options: create a new app, open a packaged app, and open a hosted app:

    Create a new app

    Select "New App..." to create a new app. You'll see a dialog offering you a choice between two templates, "Privileged Empty App" and "Privileged App".

    Both templates are from Mozilla's app template collection, and provide you with the basic structure you need to get started. The "Privileged App" shows how an app can use permissions to load cross-origin content.

    Once you've selected a template you'll be asked to name the app and select a directory to store the files, and then the new app is opened in the project editor.

    Open a packaged app

    Select "Open Packaged App..." to open a packaged app. You'll be asked to select a directory containing the app's manifest, and the app will be opened in the project editor.

    Open a hosted app

    Select "Open Hosted App..." to open a hosted app. You'll be asked to enter a URL pointing to the app's manifest, and the app will be opened in the project editor.

    Editing apps

    The project editor provides an environment for editing apps. There's a tree view on the left of all the files in the app: you can add and delete files here using a context menu. There's an editor pane on the right.

    The app summary page

    When you first open or create an app, the editor pane is occupied by the app summary page, which is as shown below:

    You can always get back to the app summary page by clicking on the root of the tree on the left.

    Manifest validation

    WebIDE automatically checks the manifest for certain common problems. If it finds a problem it indicates that the app is invalid and describes the problem in the app's summary:

    Of course, you can edit the manifest.webapp file right in the project editor as well.

    The source editor

    WebIDE uses the CodeMirror source editor.

    Source editor shortcuts

    This table lists the default shortcuts for the source editor.

    In the Editor Preferences section of the developer tools settings, you can choose to use Vim, Emacs, or Sublime Text key bindings instead.

    To select these, visit about:config, select the setting devtools.editor.keymap, and assign "vim" or "emacs", or "sublime" to that setting. If you do this, the selected bindings will be used for all the developer tools that use the source editor. You need to reopen the editor for the change to take effect.

    From Firefox 33 onwards, the key binding preference is exposed in the Editor Preferences section of the developer tools settings, and you can set it there instead of about:config.

      Windows OS X Linux
    Go to line Ctrl + J Cmd + J Ctrl + J
    Find in file Ctrl + F Cmd + F Ctrl + F
    Find again Ctrl + G Cmd + G Ctrl + G
    Select all Ctrl + A Cmd + A Ctrl + A
    Cut Ctrl + X Cmd + X Ctrl + X
    Copy Ctrl + C Cmd + C Ctrl + C
    Paste Ctrl + V Cmd + V Ctrl + V
    Undo Ctrl + Z Cmd + Z Ctrl + Z
    Redo Ctrl + Shift + Z / Ctrl + Y Cmd + Shift + Z / Cmd + Y Ctrl + Shift + Z / Ctrl + Y
    Indent Tab Tab Tab
    Unindent Shift + Tab Shift + Tab Shift + Tab
    Move line(s) up Alt + Up Alt + Up Alt + Up
    Move line(s) down Alt + Down Alt + Down Alt + Down
    Comment/uncomment line(s) Ctrl + / Cmd + / Ctrl + /

    Code completion

    When editing CSS and JavaScript, the editor provides autocomplete suggestions. CSS autocompletion is always enabled:

    To display autocomplete suggestions in JavaScript press Control + Space:

    Inline documentation

    The editor also shows inline documentation for JavaScript. Press Shift + Space to see a popup containing documentation for the symbol your cursor is on:

    Clicking the [docs] link in the popup will take you to the MDN page for the symbol.

    Saving files

    For changes to your files to take effect you need to save them. Files with unsaved changes get an asterisk next to their name in the tree view, and you can save files using the menu or Control+S (Command+S on Mac OS X).

    Removing projects

    To remove an app from WebIDE, go to the app summary page and click "Remove Project".

    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.

    Examples

    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"
      }
    }

    Running and debugging 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:

    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.

    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.
    • 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.

    Note: As indicated above, to enable unrestricted privileges on a real device through WebIDE you'll need a rooted device. There is however 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.

    Monitoring performance

    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.

    Troubleshooting

    If you have any problems working with WebIDE, see the Troubleshooting page.

     

     

    Document Tags and Contributors

    Last updated by: lUSa,