webview

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: MIT Imports: 5 Imported by: 0

README

webview

GoDoc

This package provides minimal bindings for WKWebView on OSX. The API is loosely based off of zserge/webview; however, this package only supports one platform, OSX.

All of the functions in this package must be called from the main thread. To achieve that, you can use Dispatch, which schedules a function to be called back sometime in the future.

Remember to call Loop after you initialize the WebView.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DispatchCallback

type DispatchCallback func()

type ScriptCallback

type ScriptCallback func(string)

type WebView

type WebView struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"github.com/KnownUnown/webview"
	"net/url"
)

func main() {
	v := webview.New()

	u, _ := url.Parse("https://google.com")
	v.Navigate(u)

	v.Loop()
}
Output:

func New

func New() *WebView

New creates a new WebView.

func (*WebView) AddUserScript

func (v *WebView) AddUserScript(s string)

AddUserScript registers the given string as a user script, that is, a script that is persistent across many Navigate calls or page loads.

func (*WebView) Close

func (v *WebView) Close()

Close closes the WebView.

func (*WebView) Dispatch

func (v *WebView) Dispatch(cb DispatchCallback)

Dispatch runs the given function on the main thread at some point in the future.

func (*WebView) Eval

func (v *WebView) Eval(s string)

Eval evaluates a JavaScript string.

func (*WebView) Loop

func (*WebView) Loop()

Loop pumps the NSApp run loop, namely, it calls `[NSApp run]`. This function must be called from the main thread to run the WebView after you create it. It blocks until the app exits.

func (*WebView) Navigate

func (v *WebView) Navigate(u *url.URL)

Navigate loads the provided URL in the WebView.

func (*WebView) SetScriptCallback

func (v *WebView) SetScriptCallback(cb ScriptCallback)

SetScriptCallback registers a function to be called whenever JavaScript calls `window.webkit.messageHandlers.webview.postMessage`.

Jump to

Keyboard shortcuts

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