webkit2

package
v0.0.0-...-f494267 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: BSD-3-Clause, ISC Imports: 10 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"
	"runtime"

	"github.com/Arsen6331/gojs"
	"github.com/gotk3/gotk3/glib"
	"github.com/gotk3/gotk3/gtk"
	"github.com/sourcegraph/go-webkit2/webkit2"
)

func main() {
	runtime.LockOSThread()
	gtk.Init(nil)

	webView := webkit2.NewWebView()
	defer webView.Destroy()

	webView.Connect("load-failed", func() {
		fmt.Println("Load failed.")
	})
	webView.Connect("load-changed", func(_ *glib.Object, i int) {
		loadEvent := webkit2.LoadEvent(i)
		switch loadEvent {
		case webkit2.LoadFinished:
			fmt.Println("Load finished.")
			fmt.Printf("Title: %q\n", webView.Title())
			fmt.Printf("URI: %s\n", webView.URI())
			webView.RunJavaScript("window.location.hostname", func(val *gojs.Value, err error) {
				if err != nil {
					fmt.Println("JavaScript error.")
				} else {
					fmt.Printf("Hostname (from JavaScript): %q\n", val)
				}
				gtk.MainQuit()
			})
		}
	})

	glib.IdleAdd(func() bool {
		webView.LoadURI("https://status.github.com/")
		return false
	})

	gtk.Main()

}
Output:

Load finished.
Title: "GitHub System Status"
URI: https://status.github.com/
Hostname (from JavaScript): "status.github.com"

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheModel

type CacheModel int

CacheModel describes the caching behavior.

See also: WebKitCacheModel at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#WebKitCacheModel.

const (
	DocumentViewerCacheModel CacheModel = iota
	WebBrowserCacheModel
	DocumentBrowserCacheModel
)

CacheModel enum values are described at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#WebKitCacheModel.

type LoadEvent

type LoadEvent int

LoadEvent denotes the different events that happen during a WebView load operation.

See also: WebKitLoadEvent at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitLoadEvent.

const (
	LoadStarted LoadEvent = iota
	LoadRedirected
	LoadCommitted
	LoadFinished
)

LoadEvent enum values are described at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitLoadEvent.

type Settings

type Settings struct {
	*glib.Object
	// contains filtered or unexported fields
}

func (*Settings) GetAutoLoadImages

func (s *Settings) GetAutoLoadImages() bool

GetAutoLoadImages returns the "auto-load-images" property.

See also: webkit_settings_get_auto_load_images at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-get-auto-load-images

func (*Settings) GetEnableWriteConsoleMessagesToStdout

func (s *Settings) GetEnableWriteConsoleMessagesToStdout() bool

GetEnableWriteConsoleMessagesToStdout returns the "enable-write-console-messages-to-stdout" property.

See also: webkit_settings_get_enable_write_console_messages_to_stdout at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-get-enable-write-console-messages-to-stdout

func (*Settings) SetAutoLoadImages

func (s *Settings) SetAutoLoadImages(autoLoad bool)

SetAutoLoadImages sets the "auto-load-images" property.

See also: webkit_settings_get_auto_load_images at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-auto-load-images

func (*Settings) SetEnableWriteConsoleMessagesToStdout

func (s *Settings) SetEnableWriteConsoleMessagesToStdout(write bool)

SetEnableWriteConsoleMessagesToStdout sets the "enable-write-console-messages-to-stdout" property.

See also: webkit_settings_set_enable_write_console_messages_to_stdout at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-write-console-messages-to-stdout

func (*Settings) SetUserAgentWithApplicationDetails

func (s *Settings) SetUserAgentWithApplicationDetails(appName, appVersion string)

SetUserAgentWithApplicationDetails sets the "user-agent" property by appending the application details to the default user agent.

See also: webkit_settings_set_user_agent_with_application_details at http://webkitgtk.org/reference/webkit2gtk/unstable/WebKitSettings.html#webkit-settings-set-user-agent-with-application-details

type WebContext

type WebContext struct {
	// contains filtered or unexported fields
}

WebContext manages all aspects common to all WebViews.

See also: WebKitWebContext at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html.

func DefaultWebContext

func DefaultWebContext() *WebContext

DefaultWebContext returns the default WebContext.

See also: webkit_web_context_get_default at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-get-default.

func (*WebContext) CacheModel

func (wc *WebContext) CacheModel() CacheModel

CacheModel returns the current cache model.

See also: webkit_web_context_get_cache_model at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-get-cache-model.

func (*WebContext) ClearCache

func (wc *WebContext) ClearCache()

ClearCache clears all resources currently cached.

See also: webkit_web_context_clear_cache at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-clear-cache.

func (*WebContext) SetCacheModel

func (wc *WebContext) SetCacheModel(model CacheModel)

SetCacheModel sets the current cache model.

See also: webkit_web_context_set_cache_model at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-set-cache-model.

type WebView

type WebView struct {
	*gtk.Widget
	// contains filtered or unexported fields
}

WebView represents a WebKit WebView.

See also: WebView at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html.

func NewWebView

func NewWebView() *WebView

NewWebView creates a new WebView with the default WebContext and the default WebViewGroup.

See also: webkit_web_view_new at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-new.

func NewWebViewWithContext

func NewWebViewWithContext(ctx *WebContext) *WebView

NewWebViewWithContext creates a new WebView with the given WebContext and the default WebViewGroup.

See also: webkit_web_view_new_with_context at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-new-with-context.

func (*WebView) Context

func (v *WebView) Context() *WebContext

Context returns the current WebContext of the WebView.

See also: webkit_web_view_get_context at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-context.

func (*WebView) Destroy

func (v *WebView) Destroy()

Destroy destroys the WebView's corresponding GtkWidget and marks its internal WebKitWebView as nil so that it can't be accidentally reused.

func (*WebView) GetSnapshot

func (v *WebView) GetSnapshot(resultCallback func(result *image.RGBA, err error))

GetSnapshot runs asynchronously, taking a snapshot of the WebView. Upon completion, resultCallback will be called with a copy of the underlying bitmap backing store for the frame, or with an error encountered during execution.

See also: webkit_web_view_get_snapshot at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-snapshot

func (*WebView) JavaScriptGlobalContext

func (v *WebView) JavaScriptGlobalContext() *gojs.Context

JavaScriptGlobalContext returns the global JavaScript context used by WebView.

See also: webkit_web_view_get_javascript_global_context at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-javascript-global-context

func (*WebView) LoadHTML

func (v *WebView) LoadHTML(content, baseURI string)

LoadHTML loads the given content string with the specified baseURI. The MIME type of the document will be "text/html".

See also: webkit_web_view_load_html at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-load-html

func (*WebView) LoadURI

func (v *WebView) LoadURI(uri string)

LoadURI requests loading of the specified URI string.

See also: webkit_web_view_load_uri at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-load-uri

func (*WebView) RunJavaScript

func (v *WebView) RunJavaScript(script string, resultCallback func(result *gojs.Value, err error))

RunJavaScript runs script asynchronously in the context of the current page in the WebView. Upon completion, resultCallback will be called with the result of evaluating the script, or with an error encountered during execution. To get the stack trace and other error logs, use the ::console-message signal.

See also: webkit_web_view_run_javascript at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-run-javascript

func (*WebView) Settings

func (v *WebView) Settings() *Settings

Settings returns the current active settings of this WebView's WebViewGroup.

See also: webkit_web_view_get_settings at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-settings.

func (*WebView) Title

func (v *WebView) Title() string

Title returns the current active title of the WebView.

See also: webkit_web_view_get_title at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-title.

func (*WebView) URI

func (v *WebView) URI() string

URI returns the current active URI of the WebView.

See also: webkit_web_view_get_uri at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-uri.

Jump to

Keyboard shortcuts

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