host

package
v0.16.355 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package host owns Chrome independently of the runtime's lifetime.

Index

Constants

View Source
const DefaultDownloadLimit = 100 << 20

DefaultDownloadLimit is the largest file a page may download unless the runtime says otherwise.

View Source
const HelloMethod = "Host.hello"

HelloMethod is answered by the host itself, never by Chrome: {"build": "..."}. A host too old to know it answers with Chrome's "method not found", which is a different build too.

View Source
const LogLimit = 4 << 20

LogLimit caps the persistent host log in bytes.

Variables

View Source
var Build = "dev"

Build is the runtime's build (set by the runtime's main): a host answers it to Host.hello, and a runtime of another build replaces the host, so an update reaches the browser too.

View Source
var BuildID = sync.OnceValue(func() string {
	if Build != "dev" {
		return Build
	}
	if exe, err := os.Executable(); err == nil {
		if st, err := os.Stat(exe); err == nil {
			return Build + "+" + strconv.FormatInt(st.ModTime().UnixNano(), 36)
		}
	}
	return Build
})

BuildID is Build, with the executable's time for a dev build: every rebuild is another build.

Functions

func AllowedNavigation

func AllowedNavigation(raw string) bool

AllowedNavigation says whether a page may be opened at raw: an http(s) address without a user name, or about:blank. file:, chrome:, javascript:, data:, view-source: and the rest never become a page of the agent's Chrome; the relay refuses them for every client (Page.navigate, Target.createTarget), whatever the tool that asked.

func Main

func Main(args []string) error

Main parses the browser-host subcommand and handles termination signals.

func PrivateDir

func PrivateDir(dir string) error

PrivateDir creates an owner-only directory and rejects foreign ownership or symlinks.

func Refusal

func Refusal(raw string) string

Refusal says why the agent's browser will not open raw, in the words of a failed navigation ("" when it may). The egress refuses the same at the network; checked before, the agent learns why instead of reading a 403 page.

func Run

func Run(ctx context.Context, cfg Config) error

Run owns a profile lock, relay, display and Chrome until termination.

func Running

func Running(dir string) bool

Running checks the host's advisory lock rather than trusting stale PID files.

func SocketPath

func SocketPath(runDir, profile string) string

SocketPath keeps room for the terminating NUL on both Linux and Darwin.

func Start

func Start(executable string, cfg Config) error

Start gives the host its own session; the runtime must only ever close its client socket.

func Stop

func Stop(ctx context.Context, dir, socket string) error

Stop gracefully closes only the browser behind this profile's private relay. Waiting for the host lock also waits for Chrome's final cookie/session writes.

Types

type Config

type Config struct {
	ProfileDir, Socket, Chrome, Mode string
	NoSandbox                        *bool
	// Idle closes the host once no runtime has been connected for this long (0: never). The runtime closes an idle
	// browser it is connected to itself; this is for a runtime that went away (an update, a crash) and left it behind.
	Idle time.Duration
	// MaxTabs bounds Chrome's renderer processes (--renderer-process-limit); 0 leaves Chrome's own bound.
	MaxTabs int
	// Nice lowers Chrome's and Xvfb's priority (0 keeps it).
	Nice int
	// DownloadLimit is the largest file a page may download into the profile's downloads/; 0 refuses downloads.
	DownloadLimit int64
}

Config contains the paths and display mode for one profile host.

Jump to

Keyboard shortcuts

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