preview

package
v0.93.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 15 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 preview serves a session's checkout, and its artifact directory, over loopback HTTP, so the session's browser can load a local file without a file: URL. A file: page follows its own links to any path on the machine, and the Chromium that loads it runs outside a confined session's sandbox; it also gets a null origin, which blocks module scripts and fetch. Served from an os.Root, the directory is the whole of what the page can reach.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLocal

func IsLocal(raw string) bool

IsLocal reports whether raw names a local file, as a file: URL or an absolute path, rather than a URL the browser loads as is.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service holds one listener per served directory, opened the first time a page from it is asked for and kept until Close.

func New

func New() *Service

New returns a Service that binds the loopback interface.

func (*Service) ArtifactURL added in v0.88.0

func (s *Service) ArtifactURL(dir string, devPort int, raw string) (string, bool, error)

ArtifactURL is the http URL that serves raw when it names a file in dir, a session's artifact directory (internal/artifact), and ok is false when it does not, which leaves raw to the checkout. devPort is the session's dev-server port, 0 without one; it only places the listener.

func (*Service) Close

func (s *Service) Close() error

Close stops every listener.

func (*Service) IsNewTab

func (s *Service) IsNewTab(raw string) bool

IsNewTab reports whether raw is a new-tab page of this lich: its own origin, not any page of the machine that happens to share the path.

func (*Service) NewTabURL

func (s *Service) NewTabURL(session string) (string, error)

NewTabURL is the http URL of session's new-tab page. One listener of its own serves every session's: a page the agent wrote, from an artifact's origin, then cannot fetch the project's services and recent pages. The session is in the path, and the handler answers 404 for one it does not know.

func (*Service) SetNewTab

func (s *Service) SetNewTab(h http.Handler)

SetNewTab sets the handler of the new-tab page. Startup wiring, called before anything asks for its URL.

func (*Service) URL

func (s *Service) URL(dir string, devPort int, raw string) (string, error)

URL is the http URL that serves raw, a file: URL or an absolute path inside dir, from the checkout at dir whose dev-server port is devPort.

Jump to

Keyboard shortcuts

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