309 lines · 10.0 KB
// Package shoot photographs an application with the Chrome already on the
// machine.
//
// squint never downloads or ships a browser. An earlier tool in this family
// pinned an exact renderer in a 300MB container so that stored baseline
// images would match across machines; squint stores no baselines, so it has
// nothing to pin and borrows whatever Chrome is installed.
package shoot

import (
	"context"
	"encoding/json"
	"fmt"
	"image"
	"image/png"
	"net/http"
	"net/http/cookiejar"
	"net/url"
	"os"
	"os/exec"
	"runtime"
	"strings"
	"sync"
	"time"

	"git.mills.io/prologic/squint/internal/config"
	"github.com/chromedp/cdproto/network"
	cdpruntime "github.com/chromedp/cdproto/runtime"
	"github.com/chromedp/chromedp"
)

// Browser is a running Chrome that every shot is taken through. One
// browser for a whole shoot: starting Chrome is the slowest thing squint
// does, and a shoot takes dozens of pictures.
type Browser struct {
	ctx    context.Context
	cancel []context.CancelFunc

	// sessions caches one login per user for the life of a shoot. Logging
	// in per shot is both wasteful and wrong: a matrix of thirty-odd