Help us shape the future of Go! Take the 2026 Go Developer Survey

browserlogs

package
v1.37.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package browserlogs reports JavaScript errors from the pages lerd serves into the dashboard. A site that opts in gets a script injected into its HTML through nginx while debug capture is on; the script posts what it catches to a same-origin endpoint nginx proxies to lerd-ui, which records it.

Index

Constants

View Source
const MaxReports = 50

MaxReports caps how many entries one post may carry; the script itself stops after 50 per page.

Variables

View Source
var EventTypes = []string{"error", "rejection", "console.error", "console.warn", "network", "resource", "event", "navigation"}

EventTypes are the types a browser event is filtered and counted by, with console messages split by level the way the dashboard filters them.

Functions

func Capturable

func Capturable(s config.Site) bool

Capturable reports whether a site's vhost can carry the capture block: PHP-FPM, host-proxy and custom-container sites. FrankenPHP is left out for now, and a paused site or a sleeping host-proxy one keeps its holding page.

func EventType

func EventType(r Report) string

EventType returns a browser event's type in EventTypes terms.

func Events

func Events(body []byte, site, branch, host string) ([]dumps.Event, error)

Events turns a posted batch into browser events for the site nginx named. Entries of a type lerd does not know are dropped.

func LensURL

func LensURL(site config.Site) string

LensURL is the dashboard's Browser lens for a site, which the script names in the line it logs on load.

func PageSettings

func PageSettings(site config.Site) config.BrowserLogsSettings

PageSettings are the settings the script is served with: the site's own, with the events of its active presets added.

func RefreshVhosts

func RefreshVhosts() error

RefreshVhosts rewrites the vhosts of the sites that opted in, after the debug switch flipped, so their pages gain or lose the script. With no site opted in it does nothing, so the debug switch never reloads nginx for it.

func SaveSite

func SaveSite(site config.Site, s config.BrowserLogsSettings) error

SaveSite stores a site's settings. Only turning the site on or off touches nginx, since the vhost carries that; everything else is read when the script is served.

func Script

func Script(s config.BrowserLogsSettings, lensURL string) string

Script returns the capture script for a site's settings. A site with capture turned off gets a script that only says so, for a page cached from before it was turned off.

func SetPreset

func SetPreset(site config.Site, name string, on bool) error

SetPreset switches a store preset on or off for a site.

Types

type Entry

type Entry struct {
	Type    string `json:"type"`
	Message string `json:"message"`
	At      string `json:"at,omitempty"`
	Stack   string `json:"stack,omitempty"`
	Method  string `json:"method,omitempty"`
	Request string `json:"request,omitempty"`
	Status  int    `json:"status,omitempty"`
	Cross   bool   `json:"cross_origin,omitempty"`
	RID     string `json:"rid,omitempty"`
	Time    string `json:"time"`
}

Entry is one browser event as an assistant reads it: only the fields that say what happened and where.

type PageView

type PageView struct {
	URL    string  `json:"url"`
	Branch string  `json:"branch,omitempty"`
	Start  string  `json:"started"`
	Events []Entry `json:"events"`
}

PageView is one load of a page, or one SPA navigation, with what happened on it in order.

type PresetStatus

type PresetStatus struct {
	config.BrowserPreset
	Detected bool `json:"detected"`
	Active   bool `json:"active"`
}

PresetStatus is a store preset as it stands for one site: whether the project uses its library, and whether its events are reported.

func Presets

func Presets(site config.Site) []PresetStatus

Presets lists the store presets for a site, the detected ones first and each group by label.

type Report

type Report struct {
	Type    string `json:"type"`
	Level   string `json:"level,omitempty"`
	Message string `json:"message"`
	Stack   string `json:"stack,omitempty"`
	File    string `json:"file,omitempty"`
	Line    int    `json:"line,omitempty"`
	Col     int    `json:"col,omitempty"`
	Method  string `json:"method,omitempty"`
	Request string `json:"request,omitempty"`
	Status  int    `json:"status,omitempty"`
	Nav     string `json:"nav,omitempty"`
	Tag     string `json:"tag,omitempty"`
	Name    string `json:"name,omitempty"`
	Label   string `json:"label,omitempty"`
	Cross   bool   `json:"cross,omitempty"`
	// RID is the PHP request a failed fetch or XHR reached, read off its
	// X-Lerd-Rid response header.
	RID  string `json:"rid,omitempty"`
	URL  string `json:"url,omitempty"`
	Page string `json:"page,omitempty"`
	UA   string `json:"ua,omitempty"`
	At   string `json:"at,omitempty"`
}

Report is one entry the script posts.

type Result

type Result struct {
	Enabled  bool `json:"enabled"`
	NoChange bool `json:"no_change"`
}

Result reports the outcome of a SetSite call.

func SetSite

func SetSite(site config.Site, on bool) (Result, error)

SetSite turns browser logs on or off for one site. Its pages carry the script only while debug capture is on as well.

type Summary

type Summary struct {
	Counts    map[string]int `json:"counts"`
	PageViews []PageView     `json:"page_views"`
}

Summary is the browser events of a site grouped per page view, newest view first, with a count per type of everything that matched.

func Summarize

func Summarize(events []dumps.Event, types []string) Summary

Summarize groups browser events per page view and keeps only the types asked for; none means all. Events arrive oldest first, as the ring holds them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL