MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

Questa traduzione è incompleta. Collabora alla traduzione di questo articolo dall’originale in lingua inglese.

WebIDE è disponibile da Firefox 34 in poi.

Puoi attivare WebIDE anche in Firefox 33, semplicemente cambiando una preferenza: digita about:config nella barra degli indirizzi e imposta come vero il parametro di devtools.webide.enabled.

WebIDE è il sostituto di App Manager. Come App Manager,  ti permette di usare e fare il debug delle app di Firefox OS usando Firefox OS Simulator oppure un normale dispositivo con Firefox OS.

WebIDE include un ambiente di editing che ti permette di creare e sviluppare app per Firefox OS, fornisce una visione ad albero di tutti i file presenti nella tua app con la possibilità di modificarli e salvarli, e in più due template per aiutarti a iniziare.

Inoltre, WebIDE ti permette di connetere i Firefox Developer Tools ad altri browser, come Firefox per Android, Chrome per Android e Safari su iOS. Dai un'occhiata alla pagina Debug Remoto per ottenere informazioni su come connetterti ad un browser specifico.

Con WebIDE, per prima cosa devi impostare una o più runtime. Una runtime, è l'ambiente in cui testerai ed eseguirai il debug di un App. La runtime potrebbe essere un device con a bordo Firefox OS connesso tramite cavo USB, oppure Firefox OS Simulator installato sul computer.

Adesso, puoi creare un app, o aprire un app esistente. Se stai creando una nuova app, puoi partire da un template che include la struttura base delle cartelle e un modello contenente il minimo indispensabile per iniziare a sviluppare, oppure usare un template più corposo che mostra come usare una API privilegiata. Con WebIDE puoi modificare e salvare i file della tua app, che vengono mostratti in una struttura ad albero, attraverso un editor incorporato. Ovviamente non sei obbligato ad usare l'editor incorporato, puoi sviluppare l'app esternamente ed usare WebIDE solamente per eseguire il debug.

Infine, puoi installare l'app in  una delle runtime ed eseguirla. Durante l'esecuzione dell'app puoi osservarla e modificarla tramite gli strumenti per lo sviluppo come l'Inspector, la Console, Il Debugger Javascript e molto altro.

Requisiti di sistema

Per sviluppare ed eseguire il debug delle app utilizzando WebIDE, tutto ciò che ti serve è Firefox 23 o versioni successive.  Per testare l'app su un dispositivo vero e proprio, hai bisogno di un device che abbia Firefox OS 1.2 o versioni successive.

Puoi usare WebIDE solamente se il tuo sviluppo riguarda Firefox OS 1.2 o versioni successive.

Aprire WebIDE

WebIDE può essere aperto in tre modi:

  • Cliccando la voce "WebIDE" nel Menu Web Developer
  • Utilizzando la scorciatoia da tastiera Shift-F8.
  • Utilizzando l'icona dedicata nella barra degli strumenti. Quest'icona sarà sempre presente se utilizzi Firefox Developer Edition, e su qualsiasi versione di Firefox dalla 36 in poi dopo che hai apero WebIDE almeno una volta.

Ecco WebIDE in azione:Il menu a cascata sulla sinistra denominato "Apri App", ti permette di aprire un app esistente o di crearne una nuova, mentre il menu sulla destra ti permette di scegliere una runtime o crearne una nuova.

I tasti esegui, stop e debug: appaiono solamente dopo aver aperto un app e selezionato una runtime.

Da Firefox 36, puoi modificare la grandezza del font in WebIDE utilizzando le seguenti scorciatoie da tastiera (usa il tasto Command al posto Control se stai usando OS X):

  • Ctrl +  aumenta grandezza font
  • Ctrl - diminuisci grandezza font
  • Ctrl 0 reimposta grandezza font al valore di default

Impostare le runtime

Nel menu "Seleziona Runtime", le runtime sono raggruppate in tre tipi:

  • Dispositivi USB: usa un device Firefox OS connesso tramite USB. Questa opzione ti permette, da Firefox 36, di connetterti anche a Firefox per Android.
  • Simulatori: Le istanze del Simulatore di Firefox OS che hai installato sul tuo computer.
  • Custom: usa questa opzione per connettere una runtime a WebIDE usando un nome e una porta precisa. Da Firefox 36 questo tipo di runtime è stato rinominato in "Altro". Se hai installato l'add-on Valence questa sezione conterrà anche delle runtime addizionali.

La prima volta che clicchi il menu, probabilmente non vedrai alcuna runtime:

Il resto di questa sezione mostra come fare per aggiungere delle runtime.

Connettersi ad un device Firefox OS

Prima di connetterti ad un device, ci sono alcune cose da fare:

  • controllare la tua versione di Firefox OS: assicurati che il tuo device abbia Firefox OS 1.2/Boot2Gecko 1.2 o successivi. Per controllare la versione, vai in Impostazioni  > Informazioni sul dispositivoSoftware. Se il tuo device non ha una versione supportata, leggi la Guida al Telefono per Sviluppatori e segui le istruzioni per fare l'upgrade.
  • abilita il debug remoto: nell'app Impostazioni andare in Informazioni Dispositivo > Altre Informazioni > Sviluppatore.
    • Firefox OS 1.3 e precedenti: "Debug Remoto" è una semplice casella di controllo. Spuntala.
    • Firefox OS 1.4 e successive: "Debug Remoto" richiede di abilitare solo ADB o ADB e DevTools. Selezionare "ADB e DevTools".
  • disable Screen lock on your device: in the Settings app on the device, go to Screen Lock and unchecking the Lock Screen checkbox. This is a good idea 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 is big, so it 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 is large and 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.

Custom runtimes

Remote runtime

With a custom 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 actions

When a runtime is selected, the Runtimes dropdown menu has three 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 (!)
  • 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 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.

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

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.

 

 

Tag del documento e collaboratori

 Hanno collaborato alla realizzazione di questa pagina: trueliarx, MarkCaputo
 Ultima modifica di: trueliarx,