Documentation
¶
Index ¶
- Constants
- Variables
- func LocateChrome() string
- func LocateChromium() string
- func LocateEdge() string
- func LocateGoogleChrome() string
- func PDF(url, script string, width, height int) ([]byte, error)
- func PNG(url, script string, x, y, width, height int, bg uint32, scale float32) ([]byte, error)
- func PromptDownload()
- type Bounds
- type UI
- func New(url, dir string, width, height int, customArgs ...string) (UI, error)
- func NewChromium(url, dir string, width, height int, additionalArgs ...string) (UI, error)
- func NewEdge(url, dir string, width, height int, additionalArgs ...string) (UI, error)
- func NewGoogleChrome(url, dir string, width, height int, additionalArgs ...string) (UI, error)
- func NewHtml5(executable, url, dir string, width, height int, additionalArgs ...string) (UI, error)
- type Value
- type WindowState
Constants ¶
const ( // PageA4Width is a width of an A4 page in pixels at 96dpi PageA4Width = 816 // PageA4Height is a height of an A4 page in pixels at 96dpi PageA4Height = 1056 )
Variables ¶
var AdditionalChromiumArgs = []string{
"--disable-background-networking",
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-breakpad",
"--disable-client-side-phishing-detection",
"--disable-default-apps",
"--disable-dev-shm-usage",
"--disable-extensions",
"--disable-features=site-per-process",
"--disable-hang-monitor",
"--disable-ipc-flooding-protection",
"--disable-popup-blocking",
"--disable-prompt-on-repost",
"--disable-renderer-backgrounding",
"--disable-sync",
"--disable-translate",
"--disable-windows10-custom-titlebar",
"--metrics-recording-only",
"--no-first-run",
"--no-default-browser-check",
"--safebrowsing-disable-auto-update",
"--password-store=basic",
"--use-mock-keychain",
"--remote-allow-origins=*",
}
var ChromeExecutable = LocateChrome
ChromeExecutable returns a string which points to the preferred Chrome executable file.
var ChromiumExecutable = LocateChromium
ChromeExecutable returns a string which points to the preferred Chromium executable file.
var EdgeExecutable = LocateEdge
EdgeExecutable returns a string which points to the preferred Edge executable file.
var GoogleChromeExecutable = LocateGoogleChrome
GoogleChromeExecutable returns a string which points to the preferred Google Chrome executable file.
Functions ¶
func LocateChrome ¶
func LocateChrome() string
LocateChrome returns a path to the Chrome binary, or an empty string if Chrome installation is not found.
func LocateChromium ¶ added in v0.1.12
func LocateChromium() string
LocateChromium returns a path to the Chromium binary, or an empty string if the Chromium installation is not found.
func LocateEdge ¶ added in v0.1.12
func LocateEdge() string
LocateEdge returns a path to the Edge binary, or an empty string if Edge installation is not found.
func LocateGoogleChrome ¶ added in v0.1.13
func LocateGoogleChrome() string
LocateGoogleChrome returns a path to the Google Chrome binary, or an empty string if the Google Chrome installation is not found.
func PDF ¶
PDF converts a given URL (may be a local file) to a PDF file. Script is evaluated before the page is printed to PDF, you may modify the contents of the page there of wait until the page is fully rendered. Width and height are page bounds in pixels. PDF by default uses 96dpi density. For A4 page you may use PageA4Width and PageA4Height constants.
func PNG ¶
PNG converts a given URL (may be a local file) to a PNG image. Script is evaluated before the "screenshot" is taken, so you can modify the contents of a URL there. Image bounds are provides in pixels. Background is in ARGB format, the default value of zero keeps the background transparent. Scale allows zooming the page in and out.
This function is most convenient to convert SVG to PNG of different sizes, for example when preparing Lorca app icons.
func PromptDownload ¶
func PromptDownload()
PromptDownload asks user if he wants to download and install Chrome, and opens a download web page if the user agrees.
Types ¶
type Bounds ¶
type Bounds struct {
Left int `json:"left"`
Top int `json:"top"`
Width int `json:"width"`
Height int `json:"height"`
WindowState WindowState `json:"windowState"`
}
Bounds defines settable window properties.
type UI ¶
type UI interface {
Load(url string) error
Bounds() (Bounds, error)
SetBounds(Bounds) error
Bind(name string, f interface{}) error
Eval(js string) Value
Done() <-chan struct{}
Close() error
}
UI interface allows talking to the HTML5 UI from Go.
func New ¶
New returns a new HTML5 UI for the given URL, user profile directory, window size and other options passed to the browser engine. If URL is an empty string - a blank page is displayed. If user profile directory is an empty string - a temporary directory is created and it will be removed on ui.Close(). You might want to use "--headless" custom CLI argument to test your UI code.
func NewChromium ¶ added in v0.1.12
NewChromium returns a new Chromium HTML5 UI.
func NewGoogleChrome ¶ added in v0.1.13
NewGoogleChrome returns a new Google Chrome HTML5 UI.
func NewHtml5 ¶ added in v0.1.13
NewHtml5 returns a new HTML5 UI for the given executable URL, user profile directory, window size and other options passed to the browser engine. If URL is an empty string - a blank page is displayed. If user profile directory is an empty string - a temporary directory is created and it will be removed on ui.Close(). You might want to use "--headless" custom CLI argument to test your UI code.
type Value ¶
type Value interface {
Err() error
To(interface{}) error
Float() float32
Int() int
String() string
Bool() bool
Object() map[string]Value
Array() []Value
Bytes() []byte
}
Value is a generic type of a JSON value (primitive, object, array) and optionally an error value.
type WindowState ¶
type WindowState string
WindowState defines the state of the Chrome window, possible values are "normal", "maximized", "minimized" and "fullscreen".
const ( // WindowStateNormal defines a normal state of the browser window WindowStateNormal WindowState = "normal" // WindowStateMaximized defines a maximized state of the browser window WindowStateMaximized WindowState = "maximized" // WindowStateMinimized defines a minimized state of the browser window WindowStateMinimized WindowState = "minimized" // WindowStateFullscreen defines a fullscreen state of the browser window WindowStateFullscreen WindowState = "fullscreen" )
