Repository navigation
feat: capture browser errors and page views from site pages - #2123
Conversation
|
@geodro can you do a re-run of the failed job? The CI runner is at fault in this one |
|
@ExeQue some conflict editors on this one |
A new browser capture, switched on its own and off by default, injects a script into the pages of PHP-FPM, host-proxy and custom-container sites through nginx and reports uncaught errors, unhandled rejections and page views to lerd-ui, along with console messages, failed requests, resources that failed to load and configured DOM events where the site asks for them. nginx names the site in headers it sets itself and lerd-ui only accepts reports nginx handed over. Each site's settings live under browser_capture in .lerd.yaml, or in the site registry when the project has none, and the script is served with them baked in so a change needs no nginx reload. Presets add a frontend library's own events: the store's package definitions declare them in a browser block, an npm package with the type npm, and the packages that share a preset name are offered as one, detected from the project's composer and npm packages. npm packages are read from the index's npm_packages, apart from packages, which every released lerd fetches whole on update and would refuse an npm name from, and a package type lerd does not know is reported by name and never read. The dashboard gets a Browser lens grouped per page view with a settings modal, a toggle in the Sites header and System Health, and a Debug tab on sites without PHP. MCP gains browser_events, browser_toggle and browser_presets, and the CLI gains lerd browser-capture.
f5ae289 to
3be52b4
Compare
|
@geodro thanks, those were the old editor commits still sitting under this one after the squash, dropped them and rebased the whole stack on main, the debug bar now opens files through the single editor choice main has |
Browser capture no longer has a global switch of its own. The debug switch is the only global one, and each site opts in, off by default, from the browser icon in its header, lerd browser-capture on, or browser_toggle with a site over MCP. A site's pages carry the script only while debug capture is on and the site opted in, and flipping debug rewrites the vhosts of opted-in sites alone, leaving nginx untouched when none did. Settings live in lerd's site registry rather than the project's .lerd.yaml, since turning capture on is one developer's choice and a committed file would switch it on for everyone who pulls the repo. The custom route and the per-capture console echo are gone, and console.warn is reported by default so Vue and Alpine warnings arrive without setup. Store presets are on by default when the project uses their library and can be switched off per site; their events are merged in when the script is served instead of being copied into the site's own list. The settings open in the shared modal at the app's usual width, events are edited the way domains are, page loads no longer show as rows of their own, and the console line the script logs links to the site's Browser lens. The script now prints an axios response, which Inertia's events carry, as its status, method and URL, and drops an identical report only within a second of the last one, so the same error caused again by the user is reported each time.
|
@ExeQue I pushed a commit on top of yours after testing this on real sites. Browser capture no longer has its own global switch, the debug switch is the only global one and each site opts in from a browser icon in its header, from lerd browser-capture on , or from browser_toggle with a site over MCP. The settings moved out of .lerd.yaml into lerd's site registry, since turning it on is one developer's choice and a committed file would switch it on for the whole team. I dropped the custom route and the verbose echo, made console.warn on by default, presets are now on by default when the project uses the library and can be switched off, and their events get merged in when the script is served instead of copied into the site's list. The script also prints an axios response as status, method and URL now, and it only drops an identical report within a second of the last one, so clicking the same broken thing twice shows up twice. |
The skill's description named slow sites, queries and profiling but nothing about a page that breaks in the browser, so an assistant asked why a page throws or warns had no reason to load it and never reached browser_events. Both the Claude and the Cursor descriptions now name the JavaScript errors and console warnings a site's pages report.
|
@geodro I'll migrate the same global + registry-only approach to the debugbar toggle as well. |
nginx names the site a report is for, but any page open in the same browser could still fire a simple POST at a site's /_lerd/browser endpoint and plant errors in the dashboard and in what an AI assistant reads over MCP. lerd-ui now accepts a report only when the browser says the site's own page sent it, through Sec-Fetch-Site being same-origin or, from an older browser, an Origin matching the site's host. A token in the script would not help here, since a hostile page can load the script and read what it sends.
I don't know about any debugbar; will see when I get there, but I don't want to bleed lerd interface into the sites; |
Builds on #2122; the commit after it is this pull request's own.
A browser capture, off by default and switched on by itself, injects a script into a site's pages through nginx and reports uncaught errors, unhandled rejections and page views to lerd-ui, along with console messages, failed requests, resources that failed to load and the DOM events a site asks for. nginx names the site in headers it sets itself and lerd-ui only accepts reports nginx handed over, and every page view gets an id of its own.
The dashboard gets a Browser lens grouped per page view, MCP gains browser_events, browser_toggle and browser_presets, and the CLI gains lerd browser-capture. Presets add a frontend library's own events, declared in the store's package definitions in lerd-env/frameworks#96; with a store that has none, no preset is offered and everything else works.
Refs #2088