Webapp guide#

Come la webapp si adatta nella shell#

Una app Web viene visualizzata in una vista Web all’interno di un contenitore che viene eseguito come app di Ubuntu nella shell di Ubuntu/Unity.

Dando un’occhiata più da vicino:

At the innermost level, there is a website that the developer identifies by URL. The website is rendered and runs in a Qt WebEngine based webview. The webview is provided by the pre-installed Morph browser and automatically handles things like file dialogs (using ContentHub), downloads, permissions, etc.

Lancio#

Ė possibile eseguire una webapp dal terminale con::

webapp-container URL

Per esempio::

webapp-container https://www.ubuntu.com

This simple form works, but almost every webapp uses other features as well, such as URL containment with URL patterns as described below.

Interfaccia utente#

Una webapp generalmente riempie l’intero spazio dello schermo dell’app, senza la necessità dei controlli dell’interfaccia utente presenti normalmente sui browser standard.

In some cases some navigation controls are appropriate, such as Back and Forward buttons, or an address bar. These are enabled with command line arguments:

  • `` –enable-back-forward`` Abilita la visualizzazione dei pulsanti back (indietro) e forward (avanti) nella barra degli strumenti (nella parte inferiore della finestra webapp)

  • `` –enable-address bar`` Abilita la visualizzazione della barra degli indirizzi (nella parte inferiore della finestra dell’app Web)

Modelli di URL#

Webapp authors often want to contain browsing to the target website. That is, the developer wants to control the URLs that can be opened in the webapp (all other URLs are opened in the browser). This is done with URL patterns as part of the webapp command line.

Tuttavia, molte app Web utilizzano pagine ospitate su più siti o che utilizzano risorse e pagine esterne.

Both containment and access to specified external URLs are implemented with URL patterns provided as arguments at launch time. Let’s take a closer look.

Vuoto per default#

Per impostazione predefinita, non vi è alcun contenuto URL. Supponiamo di avviare una webapp senza schemi e solo un URL iniziale come questo ::

webapp-container https://www.ubuntu.com

L’utente può raggiungere qualsiasi URL senza limiti. Ad esempio cliccando il pulsante Sviluppatore nella parte in alto, si arriva a developer.ubuntu.com, e mostra la webapp.

Suggerimento: puoi vedere la URL della pagina attuale abilitando la barra degli indirizzi con --enable-addressbar.

Semplice contenuto al sito#

Alcune volte si vuole contenere gli utenti nel sito stesso. Cioè, se il sito web è www.ubuntu.com, potrebbe essere utile contenere gli utenti di webapp solo per le sottopagine di www.ubuntu.com. Questo viene fatto aggiungendo un pattern URL con caratteri jolly al comando di avvio, come segue ::

webapp-container --webappUrlPatterns=https://www.ubuntu.com/* https://www.ubuntu.com
--Indirizzo Url del modello di webapp= indica il prossimo modello

https://www.ubuntu.com/* is the pattern The asterisk is a wildcard that matches any valid sequence of characters in a URL

With this launch command and URL pattern, the user can navigate to and open in the webapp any URL that starts with https://www.ubuntu.com/. For example, they can click on the Phone button (https://www.ubuntu.com/phone) in the banner and it opens in the webapp, or the Tablet button (https://www.ubuntu.com/tablet). But, clicking Developer opens the corresponding URL in the browser.

Tip: Make sure to specify the protocol in your starting URL, that is, use https://www.ubuntu.com instead of www.ubuntu.com. Not specifying the protocol would create an ambiguous URL and thus introduce security concerns.

More complex wildcard patterns#

Potresti voler limitare dalla webapp l’accesso solo ad alcune sottopagine del tuo sito. Questo è facile con i caratteri jolly. (I collegamenti ad altre pagine secondarie sono aperti nel browser.) Ad esempio, quanto segue consente l’accesso a www.ubuntu.com/desktop/features e www.ubuntu.com/phone/features pur non consentendo l’accesso a www.ubuntu.com/ desktop o www.ubuntu.com/phone

webapp-container --webappUrlPatterns=https://www.ubuntu.com/*/features https://www.ubuntu.com

Modelli multipli#

Puoi utilizzare modelli multipli separandoli con una virgola. Ad esempio, quanto segue consente l’accesso solo a www.ubuntu.com/desktop/features e www.ubuntu.com/phone/features ::

webapp-container --webappUrlPatterns=https://www.ubuntu.com/desktop/features,https://www.ubuntu.com/phone/features  https://www.ubuntu.com

Suggerimento: spesso sono necessari modelli multipli per ottenere il comportamento di contenimento previsto .

Aggiungere un sottodominio specifico#

Many URLs have one or more subdomains. (For example, in the following, «developer» is the subdomain: developer.ubuntu.com.) You can allow access to a single subdomain (and all of its subpages) with a pattern like this::

--webappUrlPatterns=https://developer.ubuntu.com/*

However, one usually wants the user to be able to navigate back to the starting URL (and its subpages). So, if the starting URL is https://www.ubuntu.com, a second pattern is needed::

--webappUrlPatterns=https://developer.ubuntu.com/*,https://www.ubuntu.com/*

Putting these together, here’s an example that starts on https://www.ubuntu.com and allows navigation to https://developer.ubuntu.com and subpages and back to https://www.ubuntu.com and subpages::

webapp-container --webappUrlPatterns=https://developer.ubuntu.com/*,https://www.ubuntu.com/*  https://www.ubuntu.com

Aggiunta di sottodomini con un carattere jolly#

Alcuni URL hanno più sottodomini. Ad esempio, www.ubuntu.com ha design.ubuntu.com, developer.ubuntu.com e altro ancora. Puoi aggiungere l’accesso a tutti i sottodomini con un jolly nella posizione del sottodominio ::

webapp-container --webappUrlPatterns=https://*.ubuntu.com/*  https://www.ubuntu.com

Note: An asterisk in the subdomain position matches any valid single subdomain. This single pattern is sufficient to enable browsing to any subdomain and subpages, including back to the starting URL (https://www.ubuntu.com) and its subpages.

Adding http#

Sometimes a site uses http for some of its URLs. In general this is unsafe and should be avoided, but here is an example that allows access to www.launchpad.net on both https and http inside the webapp (and all subpages due to the wildcard)::

webapp-container --webappUrlPatterns=https?://www.launchpad.net/* https://www.launchpad.net

Nota: il punto interrogativo in https ?. Questo significa che il carattere precedente (la “s”) è facoltativo. Se https è sempre richiesto allora ometti il punto interrogativo.

Argomenti a linea di comando#

Il container webapp accetta diverse opzioni per perfezionare il modo in cui ospita varie applicazioni web.

Vedi l’aiuto con ::

webapp-container --help

Nota: solo le seguenti opzioni si applicano ad Ubuntu convergente.

--fullscreen Display full screen
--inspector[=PORT] Run a remote inspector on a specified port or 9221 as the default port
--app-id=APP_ID Run the application with a specific APP_ID
--name=NAME Display name of the webapp, shown in the splash screen
--icon=PATH Icon to be shown in the splash screen. PATH can be an absolute or path relative to CWD
--webappUrlPatterns=URL_PATTERNS List of comma-separated url patterns (wildcard based) that the webapp is allowed to navigate to
--accountProvider=PROVIDER_NAME Online account provider for the application if the application is to reuse a local account.
--accountSwitcher Enable switching between different Online Accounts identities
--store-session-cookies Store session cookies on disk
--enable-media-hub-audio Enable media-hub for audio playback
--user-agent-string=USER_AGENT Overrides the default User Agent with the provided one.

Opzioni chrome (se nessuna specificata, non viene mostrato chrome di defaul)::

--enable-back-forward Enable the display of the back and forward buttons (implies --enable-addressbar)
--enable-addressbar Enable the display of a minimal chrome (favicon and title)

Nota: le altre opzioni disponibili sono specifiche per le webapp desktop. Si raccomanda di non usarle più.

Annullamento stringa User-Agent#

Alcuni siti web controllano parti specifiche dell’identità del motore Web, ovvero la stringa User-Agent, per regolare la loro presentazione o abilitare certe funzionalità. Sebbene non sia una pratica consigliata, a volte è necessario modificare la stringa predefinita inviata dal contenitore webapp.

Per cambiare la stringa dalla riga di comando, utilizzare la seguente opzione::

--user-agent-string='<string>' Replaces the default user-agent string by the string specified as a parameter

Contenimento dati del browser#

The webapp experience is contained and isolated from the browser data point of view. That is webapps do not access data from any other installed browser, such as history, cookies and so on. Other browsers on the system do not access the webapp’s data.

Storage#

Following storage options are supported: Local/Session Storage, IndexedDB and the deprecated WebSQL. FileSystem API is not supported because apps cannot access the filesystem directly.