Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "os" "runtime" "github.com/ezoic/webloop" "github.com/gotk3/gotk3/gtk" ) func main() { gtk.Init(nil) go func() { runtime.LockOSThread() gtk.Main() }() ctx := webloop.New() view := ctx.NewView() defer view.Close() view.Open("http://google.com") err := view.Wait() if err != nil { fmt.Fprintf(os.Stderr, "Failed to load URL: %s", err) os.Exit(1) } res, err := view.EvaluateJavaScript("document.title") if err != nil { fmt.Fprintf(os.Stderr, "Failed to run JavaScript: %s", err) os.Exit(1) } fmt.Printf("JavaScript returned: %q\n", res) }
Output: JavaScript returned: "Google"
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLoadFailed = errors.New("load failed")
ErrLoadFailed indicates that the View failed to load the requested resource.
Functions ¶
This section is empty.
Types ¶
type StaticRenderer ¶
type StaticRenderer struct { // TargetBaseURL is the baseURL of the dynamic content URLs. TargetBaseURL string // Context is the WebLoop context to create views in. Context Context // WaitTimeout is the maximum duration to wait for a loaded page to set // window.$renderStaticReady. WaitTimeout time.Duration // ReturnUnfinishedPages is whether a page that has not set // window.$renderStaticReady after WaitTimeout is sent to the browser in a // (potentially) unfinished state. If false, an HTTP 502 Bad Gateway error // will be returned. // // If you are unsure of whether all accessible pages set // window.$renderStaticReady (perhaps you could forget to do so on a few // pages), then setting ReturnUnfinishedPages would suppress errors for // those pages, at the possible expense of sending out unfinished pages that // take a long time to load. ReturnUnfinishedPages bool // RemoveJavaScript indicates whether <script> tags will be removed. When // generating static HTML pages from a dynamic JavaScript app, this is often // necessary because the JavaScript expects to run on a non-bootstrapped // page. This option is not guaranteed to disable all <script> tags and // should relied upon for security purposes. RemoveScripts bool // Log is the logger to use for log messages. If nil, there is no log // output. Log *log.Logger // contains filtered or unexported fields }
StaticRenderer generates and returns static HTML based on a snapshot of a Web page's computed HTML.
func (*StaticRenderer) Release ¶
func (h *StaticRenderer) Release()
Release releases resources used by this handler, such as the view. If this handler is reused after calling Release, the view is automatically recreated.
func (*StaticRenderer) ServeHTTP ¶
func (h *StaticRenderer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements net/http.Handler.
func (*StaticRenderer) StartGTK ¶
func (h *StaticRenderer) StartGTK()
StartGTK ensures that the GTK+ main loop has started. If it has already been started by StartGTK, it will not start it again. If another goroutine is already running the GTK+ main loop, StartGTK's behavior is undefined.
type View ¶
View represents a WebKit view that can load resources at a given URL and query information about them.
func (*View) Close ¶
func (v *View) Close()
Close closes the view and releases associated resources. Ensure that Close is called after all other pending operations on View have returned, or they may hang indefinitely.
func (*View) EvaluateJavaScript ¶
EvaluateJavaScript runs the JavaScript in script in the view's context and returns the script's result as a Go value.