Documentation ¶
Index ¶
- Variables
- func SetCustomCertificates(certs []*x509.Certificate) error
- func SetDebug(enable bool) error
- func SetDirectory(folder string) error
- func SetProxy(u *url.URL) error
- type CacheManager
- type Config
- type CookieData
- type CookieFeatures
- type CookieManager
- type DataLooper
- type DataManager
- type Event
- type JavascriptInstallationTime
- type JavascriptManager
- type NavigationEvent
- type Point
- type StorageData
- type StorageManager
- type TitleEvent
- type WebView
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotInstalled is returned when the webview is not installed. // Usually when WebView2 is not installed, see installview package for // more information of how install it. ErrNotInstalled = errors.New("webview is not installed") // ErrInvalidURL is returned when the URL is invalid. ErrInvalidURL = errors.New("invalid URL") // ErrInvalidSize is returned when the size is invalid. ErrInvalidSize = errors.New("invalid size") // ErrInvalidAuthProxy is returned when the proxy is invalid. ErrInvalidAuthProxy = errors.New("proxy with user and password is not supported") // ErrInvalidProxy is returned when the proxy is invalid. ErrInvalidProxy = errors.New("invalid proxy") // ErrInvalidCert is returned when the certificate is invalid. ErrInvalidCert = errors.New("invalid certificate") // ErrInvalidOptionChange is returned when an option is changed after the webview is created. ErrInvalidOptionChange = errors.New("invalid option change") // ErrNotSupported is returned when a feature is not supported. ErrNotSupported = errors.New("feature not supported") // ErrJavascriptManagerNotSupported is returned when the javascript manager is not supported. ErrJavascriptManagerNotSupported = errors.New("javascript manager not supported") // ErrJavascriptCallbackDuplicate is returned when the javascript callback is duplicated. ErrJavascriptCallbackDuplicate = errors.New("javascript callback is duplicated") // ErrJavascriptCallbackInvalidName is returned when the javascript name is too long. ErrJavascriptCallbackInvalidName = errors.New("javascript name is too long") // ErrInvalidJavascript is returned when the javascript is invalid. ErrInvalidJavascript = errors.New("invalid javascript") )
Functions ¶
func SetCustomCertificates ¶
func SetCustomCertificates(certs []*x509.Certificate) error
SetCustomCertificates sets additional certificates to use for the webview. It's applied for all viewers, and must be called before creating any WebView.
Only supported by Windows and Android.
func SetDebug ¶
SetDebug enables the debug (such as the inspector) for the webview. It's applied for all viewers, and must be called before creating any WebView.
Only supported by macOS, iOS and Android.
func SetDirectory ¶
SetDirectory sets the folder to use for the webview. It's applied for all viewers, and must be called before creating any WebView.
Only supported by Windows.
Types ¶
type CacheManager ¶
type CacheManager interface { // ClearAll deletes all cached data. That will delete: Cache, IndexedDB, // Cookies, SessionStorage and LocalStorage. ClearAll() error }
CacheManager can modify cache and all type of storage.
type CookieData ¶
type CookieData struct { Name string Value string Domain string Path string Expires time.Time Features CookieFeatures }
CookieData is a cookie data.
type CookieFeatures ¶
type CookieFeatures uint64
CookieFeatures is a set of cookie features.
const ( // CookieSecure is a secure cookie. CookieSecure CookieFeatures = 1 << iota // CookieHTTPOnly is a http only cookie. CookieHTTPOnly )
func (CookieFeatures) IsHTTPOnly ¶
func (f CookieFeatures) IsHTTPOnly() bool
IsHTTPOnly returns true if the cookie is http only.
func (CookieFeatures) IsSecure ¶
func (f CookieFeatures) IsSecure() bool
IsSecure returns true if the cookie is secure.
type CookieManager ¶
type CookieManager interface { // Cookies returns the cookies for the current page or all browser. Cookies(fn DataLooper[CookieData]) (err error) // AddCookie adds a cookie/local-storage item. // The cookie must be a valid cookie string, without semi-colon, space, or comma. // // If the cookie doesn't have a domain, it may be set to the current page domain, // or the browser default domain. AddCookie(c CookieData) error // RemoveCookie removes a cookie/local-storage item. RemoveCookie(c CookieData) error }
CookieManager can access and modify cookies from Webview.
Cookies might be shared between Webview instances, under the same app or device.
type DataLooper ¶
type DataLooper[T CookieData | StorageData] func(d *T) (next bool)
DataLooper receives one or more data chunks. The pointer to the data is valid until the next call to DataLooper, you must use/copy it before the end of the call.
The function must return true to continue receiving data.
type DataManager ¶
type DataManager interface { CookieManager StorageManager CacheManager }
DataManager is a data manager for the webview.
type JavascriptInstallationTime ¶
type JavascriptInstallationTime int64
JavascriptInstallationTime defines when the JavaScript code is injected.
const ( // JavascriptOnLoadStart ensures that the JavaScript code is injected on page load start, // before the page is fully loaded. JavascriptOnLoadStart JavascriptInstallationTime = iota // JavascriptOnLoadFinish ensures that the JavaScript code is injected on page load end, when // all contents are loaded. JavascriptOnLoadFinish )
type JavascriptManager ¶
type JavascriptManager interface { // RunJavaScript execute the given JavaScript code into the loaded page. // // The behavior of this function is undefined if the page is not loaded. RunJavaScript(js string) error // InstallJavascript installs the given JavaScript code as a function, // that will be injected into the page when it is loaded. // // The behavior of this function is undefined if the page is already loaded. InstallJavascript(js string, when JavascriptInstallationTime) error // AddCallback registers a callback for the given JavaScript function. // // The function can be called as follows: // // window.callback.<name>(<message>); // // The function will be called with the message provided by the JavaScript caller, // you probably want to encode (in JSON/Protobuf/Flatbuffers/Karmem/CapNProto or // another more efficient format). Due to different browser implementations and memory layouts, it's not possible to // pass a pointer to a struct to the JavaScript function or another type rather than // a string. // // It may introduce performance penalties, so use it wisely. In order to be compatible // with multiples webviews and OSes, it may introduce more indirection and use ProxyAPI // and ReflectionAPI and other slow APIs to achieve the same functionality // // If you want to return a result to the JavaScript caller, use RunJavaScript and // set the result into some array or global variable. // // The name must be unique and must not contain any dots, and must have a maximum // length of 255 characters. AddCallback(name string, fn func(message string)) error }
type NavigationEvent ¶
type NavigationEvent struct {
}NavigationEvent is issued when the URL is changed in the WebView.
func (NavigationEvent) ImplementsEvent ¶
func (NavigationEvent) ImplementsEvent()
type StorageData ¶
StorageData is a LocalStorage data.
type StorageManager ¶
type StorageManager interface { // LocalStorage returns the local storage for the current page. LocalStorage(fn DataLooper[StorageData]) (err error) // AddLocalStorage adds a local storage item. AddLocalStorage(c StorageData) error // RemoveLocalStorage removes a local storage item. RemoveLocalStorage(c StorageData) error // SessionStorage returns the session storage for the current page. SessionStorage(fn DataLooper[StorageData]) (err error) // AddSessionStorage adds a session storage item. AddSessionStorage(c StorageData) error // RemoveSessionStorage removes a session storage item. RemoveSessionStorage(c StorageData) error }
StorageManager can access and modify LocalStorage, SessionStorage and other storage devices from Webview.
type TitleEvent ¶
type TitleEvent struct {
Title string
}
TitleEvent is issued when the Title of the website is changed in the WebView.
func (TitleEvent) ImplementsEvent ¶
func (TitleEvent) ImplementsEvent()
type WebView ¶
type WebView interface { // Configure sets the configuration for the webview. Configure(config Config) // Resize resizes the webview to the specified size. // To make it invisible, set the size to (0, 0). // To make it visible, set the size to a non-zero value. // // The offset is the position of the webview relative to window coordinates, // assuming 0,0 as the top-left corner of the window. Resize(size Point, offset Point) Navigate(url *url.URL) // Close closes and terminate the webview. Close() // Events returns actions that occur on the WebView. Events() chan Event // DataManager returns the DataManager for the webview. DataManager() DataManager // JavascriptManager returns the JavascriptManager for the webview. JavascriptManager() JavascriptManager }
WebView is a webview.