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
- Variables
- func Capturable(s config.Site) bool
- func EventType(r Report) string
- func Events(body []byte, site, branch, host string) ([]dumps.Event, error)
- func LensURL(site config.Site) string
- func PageSettings(site config.Site) config.BrowserLogsSettings
- func RefreshVhosts() error
- func SaveSite(site config.Site, s config.BrowserLogsSettings) error
- func Script(s config.BrowserLogsSettings, lensURL string) string
- func SetPreset(site config.Site, name string, on bool) error
- type Entry
- type PageView
- type PresetStatus
- type Report
- type Result
- type Summary
Constants ¶
const MaxReports = 50
MaxReports caps how many entries one post may carry; the script itself stops after 50 per page.
Variables ¶
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 ¶
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 Events ¶
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 ¶
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.
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"`
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.