Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/WKWebViewSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function(webfront_add_wkwebview_tests)
add_executable(wkwebview_lifecycle "${webtest_source_dir}/WKWebViewLifecycle.cpp"
"${webtest_source_dir}/WKWebViewHeaderConsumer.cpp")
target_link_libraries(wkwebview_lifecycle PRIVATE WebFront WebFront_warnings WebFront_options)
foreach(mode repeated-show main-thread native-close quit navigation-diagnostic startup-timeout settings translucent-background hidden-scheduling hidden-secondary redirect-policy missing-response committed-navigation agent-application download choose-file cancel-choose replaced-download choose-in-blank choose-in-srcdoc close-with-open-panel close-with-save-panel script-dialogs close-with-script-dialog sandboxed-script-dialog load-reveal present-timeout)
foreach(mode repeated-show main-thread native-close quit navigation-diagnostic startup-timeout settings translucent-background hidden-scheduling hidden-secondary secondary-scheduling redirect-policy missing-response committed-navigation agent-application download choose-file cancel-choose replaced-download choose-in-blank choose-in-srcdoc close-with-open-panel close-with-save-panel script-dialogs close-with-script-dialog sandboxed-script-dialog load-reveal present-timeout)
add_test(NAME WKWebViewLifecycle-${mode} COMMAND wkwebview_lifecycle ${mode})
webfront_set_browser_test_properties("WKWebViewLifecycle-${mode}" "${webtest_source_dir}" 90)
endforeach()
Expand Down
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ these entries stays in the GitHub releases and the Git history.

### Added
- Open the inspectors from the WebFront tab's menu of the developer environment: each panel shows in a floating window of the page and can be detached to a native secondary window (WebKitGTK, WKWebView, WebView2) or, with `trustLoopbackClients`, a tab of the system browser; the choice and the place are kept per project (#680, ADR-027, `docs/DEVELOPER_ENVIRONMENT.md`).
- See in the **Functions** panel of the inspectors what the application registered: each `cppFunction` with its signature written in TypeScript, the file and line of its registration, whether it receives the calling `UI`, its calls, failures, last error and durations, then the JavaScript functions that C++ calls; sort, search, and choose the refresh period (#681, ADR-027, `docs/DEVELOPER_ENVIRONMENT.md`).
- See in the **Browsers and tasks** panel the connected browsers (embedded view or external browser, local client, pending writes and calls), the running tasks of the server and the application's terminal commands (#681, ADR-027).
- Read the same registry from C++ with `app.registeredFunctions()` (#681, ADR-027).
- Declare what the inspectors show with `app.watch(name, source)`, whose handle removes the watch when it is destroyed; the Watches panel follows their registrations and removals. Outside the developer environment and in a distribution build, `watch` registers nothing (#680, ADR-027).
- Embed a plain interface directory (HTML, JavaScript, CSS, vendored files) from CMake with `webfront_embed_directory(app ui CLASS AppUI)`, without the developer environment: the build regenerates the provider when a file changes, and `fs::DocumentRootFirstFSWith<AppUI>` lets a development root serve in front of it (#675, `docs/EMBEDDED_ASSETS.md`).
- Set from the configuration `Referrer-Policy` (`contentPolicy.referrerPolicy`: `"no-referrer"` forbids explicitly that a capability in your URLs leaves in `Referer`), `X-Content-Type-Options: nosniff` (`noSniff`) and the `Cache-Control` of HTML pages (`htmlCacheControl`), on files, route and generated replies unless a reply sets its own (#674, `docs/CONTENT_POLICY.md`).
Expand All @@ -29,11 +32,13 @@ these entries stays in the GitHub releases and the Git history.
- The test helpers, `webfront_add_jasmine_test` included, export the real `XDG_DATA_HOME` and `XDG_CACHE_HOME` as `WEBFRONT_TEST_REAL_XDG_DATA_HOME` and `WEBFRONT_TEST_REAL_XDG_CACHE_HOME`, so an application under test can keep the throwaway WebKitGTK profile away from the programs it starts ([#664](https://github.com/ambroise-leclerc/WebFront/issues/664), `docs/CONSUMER_TESTING.md`).

### Changed
- The inspectors show where each `cppFunction` was registered; existing calls of `cppFunction` and `Space::cppFunction` compile unchanged (#681, ADR-027).
- `WebFront.js` opens its WebSocket on the directory of the page (`ws://host/dir/` instead of `ws://host`), which tells the server a page's space (#671) and lets an application be deployed under a sub-path of a site (#672).
- A request whose path holds a control character (`%00`...) is refused with 400, as a `..` already was, instead of being looked up as a file (#672).
- A `+` in the path of a file request is a literal `+`, as for the routes, the spaces and `ui.path()`: `/a+b.html` serves `a+b.html`, no longer `a b.html`, which `/a%20b.html` names (#672).

### Fixed
- A closed WKWebView secondary window, or one that another window covered, no longer leaves its page suspended and connected to the application: on macOS 14+ a secondary window is never suspended while inactive (#681, `docs/WKWEBVIEW.md`).
- An invalid content policy (an origin of `bridgeAllowedOrigins` or `navigationAllowedOrigins`, a `referrerPolicy`, a `htmlCacheControl`) throws `std::invalid_argument` before the server binds its port, as documented, instead of an "address already in use" error when that port is taken (#674).
- `DeveloperBrowserIntegration-workspace` gives the relaunched bootstrap page the same 60 s to start as the first one, instead of 10 s, which a loaded runner exceeded while the page verified its cached environment (#660).
- Applications started from the terminal of a Snap-packaged editor (VSCodium) now run on WebKitGTK without cleaning the environment by hand; `WEBFRONT_KEEP_SNAP_ENVIRONMENT=1` opts out (#662, `docs/WEBKITGTK.md`).
Expand Down
26 changes: 25 additions & 1 deletion docs/DEVELOPER_ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,31 @@ environment's `mount`, not to the embedded bootstrap page):
The **Watches** panel lists the application's watches (`app.watch(name, source)`, declared after `bootstrap()`): their
name, the kind of their root and where they were declared. It asks C++ for the revision of their table every 250 ms
(Pause stops it), reads the list again when it changed, and adds or removes the watches that appeared or disappeared.
Their contents, and the other panels, come with the next versions of the environment.
Their contents come with the next versions of the environment.

The **Functions** panel lists what the application registered with `cppFunction`, the functions of its spaces included
(with the path of their space): the name, the signature as TypeScript declares it (`(a: number, b: string) =>
Promise<string>`; the calling `UI` is not a parameter of JavaScript), the file and line of the registration, the number
of calls and of failures, the last error, and the mean and longest duration. **Caller** tells whether the function
receives the calling `UI`: one that does not cannot check `ui.isLocalClient()`, which a callback that writes the project,
starts a process or exposes a sensitive state must do itself (ADR-027, section 2). **Answer** tells a function that
returns a task (`ResultTask`), whose Promise settles when the task completes. A second table lists the JavaScript
functions that C++ called (`jsFunction`, `jsFunctionSender`, `broadcast`, a broadcast counting once) with the failures
of the typed calls. WebFront's own functions (`webfront.developer.*`, `webfront.commands.*`) are hidden until the
checkbox asks for them. A header sorts by its column (a second click reverses), the search field keeps the rows that
hold every word typed, and the values are read again every 250 ms, 1 s or 5 s, as chosen, until Pause.

The counters cost an atomic increment per call whether or not an inspector is open (about 12 ns measured, see
`introspection_benchmark`); the durations are measured only while this panel reads, and for five seconds after its
last read, so a function shows `–` until one of its calls was timed. A distribution build records nothing.
`app.registeredFunctions()` gives the same registry to C++ code.

The **Browsers and tasks** panel lists the connected browsers: whether each is an embedded view or an external browser,
whether it is a local client (`ui.isLocalClient()`), its state, the path its bridge was opened from and its space, the
frames not yet written to it, the typed calls of C++ whose result it has not returned, and its calls that a C++
callback has not answered yet. It also gives the number of running tasks of the server's scope (connections, bridge
loops and the application's coroutines) and the application's terminal commands (`webfront::Commands`). The other
panels come with the next versions of the environment.

The tab is a button (`aria-expanded`, `aria-haspopup="menu"`, 44 px target), its menu a `menu` of `menuitem`s of 44 px,
and the window a non-modal dialog. The interface stays in the preview
Expand Down
3 changes: 3 additions & 0 deletions docs/WKWEBVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,6 @@ retained lifecycle cases.

Hidden sessions require macOS 14+ and use the public `WKPreferences::inactiveSchedulingPolicy` value `None` so
asynchronous bridge and Worker work continues after the load event. Visible sessions retain macOS 13.3 support.
On macOS 14+, a secondary window (`openSecondaryWindow()`) uses the same policy, visible or not: closing it hides it
before its view is released, and an occluded window is inactive all along, so a suspended page would keep its
connection after its window closed. The first visible window keeps WebKit's default policy.
55 changes: 55 additions & 0 deletions docs/adr/ADR-027-inspecteurs-de-l-etat-de-l-application.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| Version | Date | État | Auteur | Évolution | Révision Git |
| --- | --- | --- | --- | --- | --- |
| 1.2 | 2026-11-26 | Proposée | Ambroise Leclerc | Registre introspectable (#681) : pages `webfront.inspector.functions`, `jsFunctions` et `browsers` (section 7) ; enregistrements tenus par les gestionnaires, donc retirés avec une fonction d'espace ; fonctions `webfront.inspector.*` non listées ; durée mesurée pendant une fenêtre de 5 s après chaque lecture des fonctions ; appels vers JavaScript comptés par nom, 1 024 noms au plus, seulement une fois l'environnement monté ; `BasicWF::registeredFunctions()` pour l'application. | À renseigner après intégration. |
| 1.1 | 2026-11-25 | Proposée | Ambroise Leclerc | Hôte détachable (#680) : `webfront.inspector.embedded()` dit à la page hôte si elle peut tourner dans un frontend intégré (vue prouvée, ou frontend actif qui transmet la preuve), ce qui décide de l'onglet du navigateur système ; `webfront.inspector.closeWindow(panneau, hôte)` ferme la fenêtre d'un panneau rattaché ; une fenêtre par panneau et par page hôte, qui seule le rattache ; choix et place conservés dans `inspector-window.json`, lus avec le jeton de leurs octets par `webfront.inspector.readPreferences()`. | À renseigner après intégration. |
| 1.0 | 2026-11-25 | Proposée | Ambroise Leclerc | Décision initiale (#678, épique #677) : inspecteurs réservés à l'environnement développeur, accès réservé aux vues prouvées sauf autorisation explicite, nœuds d'arbre sur les types existants du pont, lecture et différences paginées, opérations entières sous le verrou ou sur l'exécuteur de l'application, modification à la demande de l'application, page unique `inspector.html` dans un conteneur choisi sur l'accès effectif. | À renseigner après intégration. |

Expand Down Expand Up @@ -639,6 +640,60 @@ générées, le nombre d'appels et d'échecs, la dernière erreur et la durée m
atomiques relâchés ; la durée n'est mesurée que pendant qu'un inspecteur est ouvert, pour qu'une application sans
inspecteur n'en paie pas le coût.

**Ce qui est enregistré.** À chaque `cppFunction` (de l'application ou d'un espace, `Space::cppFunction`), WebFront
garde un enregistrement : le nom, la signature, le fichier et la ligne, le chemin de l'espace propriétaire (vide pour
l'application), si le premier paramètre est l'appelant (`UI`), et si la fonction rend un émetteur (`ResultTask`), donc
répond plus tard. L'enregistrement appartient au gestionnaire de la fonction : un enregistrement refusé (nom déjà pris)
ou une fonction d'espace libérée avec son espace disparaît du registre sans autre retrait. Les fonctions
`webfront.inspector.*` ne sont pas enregistrées : leurs compteurs ne mesureraient que l'inspecteur. Les autres fonctions
réservées (`webfront.developer.*`, `webfront.commands.*`) le sont, et le panneau les masque par défaut.

**Signature.** Elle s'écrit `(a: number, b: string) => Promise<string>` : les types sont ceux que JavaScript donne ou
reçoit par le pont (`boolean`, `number`, `string`, le tableau typé d'un conteneur de nombres, `Uint8Array` pour un
`std::bitset`, `[A, B]` pour un tuple ou une paire, `T[]` pour une liste, `void`, et `unknown` pour un type que le pont
ne transporte pas) ; l'appelant `UI` n'est pas un paramètre de JavaScript et n'y figure pas ; le résultat est toujours
une `Promise`, celle de la valeur de la tâche pour une fonction différée. Les noms des paramètres, que C++ ne donne pas,
sont `a`, `b`, … La signature est bornée à 512 octets.

**Compteurs.** Chaque appel reçu incrémente `appels` ; un appel qui ne rend pas de résultat incrémente `échecs` et
remplace la dernière erreur (texte borné à 256 octets, caractères de contrôle rendus visibles) : arguments mal formés,
exception du callback, résultat qui ne s'encode pas, et, pour une fonction différée, tâche qui échoue ou qui est arrêtée
(déconnexion du navigateur, arrêt de l'application : le code `webfront.cancelled`). La durée va de la réception à la
réponse, donc jusqu'à la fin de la tâche pour une fonction différée.

**Coût.** Sans inspecteur, un appel coûte un incrément atomique relâché et la lecture d'un drapeau, sans horloge ni
verrou : une douzaine de nanosecondes mesurées (`introspection_benchmark`, Release), contre plusieurs microsecondes
pour un appel du pont. Chaque lecture de `functions` ouvre la mesure des durées pour cinq secondes ; le premier appel
qui suit cette fenêtre, et qui lit l'horloge de toute façon, la referme. Un appel mesuré coûte deux lectures d'horloge
(environ 70 ns). Une construction de distribution n'enregistre rien et ne compte rien.

**Fonctions JavaScript appelées par C++.** Une fois l'environnement développeur monté, chaque appel de `jsFunction`
(typé ou non), chaque démarrage d'un `jsFunctionSender` et chaque `broadcast` (compté une fois, quel que soit le nombre
de navigateurs) incrémente le compteur de son nom ; un appel typé dont le futur ou l'émetteur se termine en erreur
incrémente ses échecs (une annulation locale n'est pas un échec). Les noms sont comptés un à un jusqu'à 1 024 ; les
appels des noms suivants sont comptés ensemble, pour qu'une application qui fabrique ses noms ne fasse pas croître la
table sans borne. Avant le montage de l'environnement, et en distribution, aucun appel n'est compté.

**Pages.** Trois fonctions réservées, soumises au prédicat de la section 2, rendent des pages bornées comme celles de
la section 3 (au plus 1 000 lignes, réduites à `responseBudget`, chaque ligne bornée de sorte qu'une page d'une ligne
tienne dans `minPageBytes`) :

- `webfront.inspector.functions(après, nombre)` rend `(lignes, suivant)`. Une ligne est le tuple `(identifiant, nom,
signature, fichier:ligne, espace, drapeaux, appels, échecs, dernière erreur, durée moyenne en ms, durée maximale en
ms)` ; les drapeaux valent 1 (reçoit l'appelant), 2 (réponse différée), 4 (au moins un appel mesuré : sans ce bit les
durées ne signifient rien). Le curseur est l'identifiant de la dernière ligne servie, stable sous les retraits ;
- `webfront.inspector.jsFunctions(après, nombre)` rend `(lignes, suivant)`, une ligne étant `(identifiant, nom, appels,
échecs des appels typés)` ;
- `webfront.inspector.browsers(à partir de, nombre)` rend `(lignes, suivant, tâches)`. Une ligne est `(identifiant,
drapeaux, chemin, espace, écritures en attente, résultats attendus d'appels typés de C++, appels du navigateur sans
réponse)` ; les drapeaux valent 1 (vue prouvée), 2 (client local, `isLocalClient`), 4 (démarré), 8 (fermé, en cours de
libération), 16 (la connexion qui demande). L'identifiant d'une connexion peut valoir 0 : le curseur est donc le
premier identifiant de la page suivante, 0 à la fin. `tâches` est le nombre de tâches de la portée du serveur qui ne
sont pas terminées (connexions, boucles du pont, coroutines de l'application).

Les commandes de l'application (`Commands.hpp`) se lisent par `webfront.commands.list`, qui existe déjà et garde le
contrôle d'origine (section 2). L'application lit le même registre sans le pont par `BasicWF::registeredFunctions()`.

### 8. Une page, trois conteneurs

Les inspecteurs sont une seule page de l'environnement, `inspector.html`, qui parle à C++ par le pont.
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ verification evidence remain in [PROJECT_STATUS](../PROJECT_STATUS.md).
| [ADR-024](ADR-024-tls-integre.md) | Optional integrated TLS 1.3 server | Proposed | 2026-11-21 | 1.0 |
| [ADR-025](ADR-025-mcp-http-dans-l-application.md) | The application serves MCP over Streamable HTTP on its own loopback listener, with a session Bearer token, strict Host/Origin checks, per-instance discovery and no automation in distribution builds; the webfront-agent launcher is removed; amends ADR-019 | Accepted (delivery in progress) | 2026-11-21 | 1.3 — 2026-11-22 |
| [ADR-026](ADR-026-configuration-mcp-persistante.md) | Stable MCP client configuration with explicit development security modes | Accepted | 2026-11-22 | 1.2 — 2026-11-22 |
| [ADR-027](ADR-027-inspecteurs-de-l-etat-de-l-application.md) | Application state inspectors in the developer environment only: reserved `webfront.inspector.*` functions refused to unproven views unless the application trusts loopback clients, tree nodes on existing bridge types with paged reads and paged differences, observer operations run whole under the application's lock or on its executor, writes only when the application provides them, one `inspector.html` page, shown in a floating window of the page and, for a detached panel only, in the first container that grants access (a native secondary window, else a system-browser tab) | Proposed | 2026-11-25 | 1.1 — 2026-11-25 |
| [ADR-027](ADR-027-inspecteurs-de-l-etat-de-l-application.md) | Application state inspectors in the developer environment only: reserved `webfront.inspector.*` functions refused to unproven views unless the application trusts loopback clients, tree nodes on existing bridge types with paged reads and paged differences, observer operations run whole under the application's lock or on its executor, writes only when the application provides them, one `inspector.html` page, shown in a floating window of the page and, for a detached panel only, in the first container that grants access (a native secondary window, else a system-browser tab); an introspectable registry of the registered C++ functions, of the JavaScript functions C++ calls and of the connected browsers, counted with relaxed atomics and timed only while an inspector reads | Proposed | 2026-11-25 | 1.2 — 2026-11-26 |

Numbering follows the reading topics; milestones and individual file histories provide
the chronology, which does not follow the numerical order.
Expand Down
5 changes: 5 additions & 0 deletions include/webfront/Broadcast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class Broadcast {
void operator()(auto&&... ts) const {
msg::FunctionCall<typename WebFront::BufferPolicy> command;
auto frame = detail::encodeCall<Net>(command, name, std::forward<decltype(ts)>(ts)...);
// One call for the inspectors, whatever the number of browsers it reaches (ADR-027, section 7).
if constexpr (requires { webFront.jsCallCounter(name); }) {
if (const auto counter = webFront.jsCallCounter(name))
counter->called();
}
// The sending may be deferred until a starting browser's onUIStarted handlers return: it owns what it uses.
webFront.sendToStartedLinks(detail::BroadcastCall<Net>{std::move(frame).share(), name, maxPending});
}
Expand Down
Loading
Loading