Documentation
¶
Overview ¶
Package browser is the main entry point for Gost, helping create a window initialized with a script enging, connected to a server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Browser ¶
type Browser struct {
Client http.Client
ScriptHost ScriptHost
Logger log.Logger
// contains filtered or unexported fields
}
Browser contains an initialized browser with a script engine. Create new windows by calling Browser.Open.
Browser values should be closed by calling Browser.Close, or passing a context:
func TestBrowserWithClose(t *testing.T) {
handler := NewRootHttpHandler()
b := browser.New(browser.WithHandler(handler))
t.Cleanup(func() { b.Close() })
win, err := b.Open("http://example.com")
// ...
}
Passing a context:
func TestBrowserWithContext(t *testing.T) {
handler := NewRootHttpHandler()
b := browser.New(
browser.WithHandler(handler),
browser.WithContext(t.Context(),
)
win, err := b.Open("http://example.com")
// ...
}
func New
deprecated
func New(options ...BrowserOption) *Browser
New initialises a new Browser. Options can be one of
Script engine defaults to V8. This will change in the future, but a migration path is not ready.
Deprecated: This function WILL change behaviour. Previous behaviour was to default to use V8 if nothing was specified. New default will be to have not script engine
func NewBrowser
deprecated
func NewBrowser() *Browser
Deprecated: NewBrowser should not be called. Call New instead.
This method will selfdestruct in 10 commits
func NewBrowserFromHandler
deprecated
func NewFromHandler
deprecated
NewFromHandler initialises a new Browser with with an http.Handler
Deprecated: Prefer browser.New(browser.WithHandler(...)) instead.
func (*Browser) Close ¶
func (b *Browser) Close()
Close "closes" a browser, releasing resources. This will close any initialized script hosts and contexts. Has two purposes.
- Reuse a template engine, reducing engine initialization overhead.
- Release memory for non-Go engines, e.g., V8
The relevance depends mostly on the script engine. For a pure Go engine, resources would be garbage collections. And the ability to reuse a preconfigured engine depends on engine capabilities.
Note: If a browser is initialized by passing a context.Context to the WithContext option, it will be closed if the context is cancelled.
func (*Browser) NewWindow ¶ added in v0.5.1
func (b *Browser) NewWindow() Window
NewWindow creates a new window. Panics if the browser has been closed
func (*Browser) Open ¶
Open will open a new html.Window, loading the specified location. If the server does not respons with a 200 status code, an error is returned.
See html.NewWindowReader about the return value, and when the window returns.
type BrowserOption ¶ added in v0.5.1
type BrowserOption func(*browserConfig)
func WithContext ¶ added in v0.8.0
func WithContext(ctx context.Context) BrowserOption
WithContext passes a context.Context than can trigger cancellation, e.g.:
- Close any open HTTP connections and disconnect from the server.
- Release resources, and reuse script hosts.
See also: Browser.Close
func WithHandler ¶ added in v0.5.1
func WithHandler(h http.Handler) BrowserOption
WithHandler configures the browser's http.Client to use an http.Roundtripper that bypasses the TCP stack and calls directly into the specified handler as a normal function call.
Note: There is a current limitation that NO requests from the browser will be sent when using this. So sites will not work if they
- Depend on content from CDN
- Depend on an external service, e.g., an identity provider.
That is a limitation that was the result of prioritising more important, and higher risk features.
func WithLogger ¶ added in v0.5.1
func WithLogger(l *slog.Logger) BrowserOption
func WithScriptEngine ¶ added in v0.9.2
func WithScriptEngine(engine html.ScriptEngine) BrowserOption
func WithScriptHost
deprecated
added in
v0.8.0
func WithScriptHost(host html.ScriptHost) BrowserOption
WithScriptHost uses a specific script host.
Deprecated: Prefer WithScriptEngine
Directories
¶
| Path | Synopsis |
|---|---|
|
browser
module
|
|
|
Package dom provides the fundamental DOM implementation for Gost-DOM.
|
Package dom provides the fundamental DOM implementation for Gost-DOM. |
|
event
Package event contains core browser event behavior
|
Package event contains core browser event behavior |
|
Package html works on top of the DOM to implement specific HTML elements.
|
Package html works on top of the DOM to implement specific HTML elements. |
|
input
|
|
|
controller
Package controller can simulate user interaction
|
Package controller can simulate user interaction |
|
key
Package key represents keys on the keyboard that the user might type.
|
Package key represents keys on the keyboard that the user might type. |
|
internal
|
|
|
clock
Package clock provides a simulated time for Gost-DOM.
|
Package clock provides a simulated time for Gost-DOM. |
|
constants
Package constants is a collection of values that are used many times in the implementation, but has no relevance to users of the library, e.g., a link to where you can file an issue when you encounter a not-implemented feature; or a feature that is not fully implemented, e.g.
|
Package constants is a collection of values that are used many times in the implementation, but has no relevance to users of the library, e.g., a link to where you can file an issue when you encounter a not-implemented feature; or a feature that is not fully implemented, e.g. |
|
gosthttp
Package gosthttp provides functionality to bypass the TCP stack.
|
Package gosthttp provides functionality to bypass the TCP stack. |
|
interfaces
Package interfaces contains go interfaces generated from IDL specs
|
Package interfaces contains go interfaces generated from IDL specs |
|
interfaces/html-interfaces
Package htmlinterfaces contains internal code representing the IDL interfaces in the HTML DOM API
[HTML DOM API]: https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API
|
Package htmlinterfaces contains internal code representing the IDL interfaces in the HTML DOM API [HTML DOM API]: https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API |
|
interfaces/url-interfaces
Package urlinterfaces contains internal code representing the IDL interfaces in the URL API
[URL API]: https://developer.mozilla.org/en-US/docs/Web/API/URL_API
|
Package urlinterfaces contains internal code representing the IDL interfaces in the URL API [URL API]: https://developer.mozilla.org/en-US/docs/Web/API/URL_API |
|
log
Package log contains functions used internally for logging to a default logger implementing slog.Logger.
|
Package log contains functions used internally for logging to a default logger implementing slog.Logger. |
|
monads/result
package result provides monadic result binding
|
package result provides monadic result binding |
|
promise
Package promise provides a Go way to represent the concept of a Promise.
|
Package promise provides a Go way to represent the concept of a Promise. |
|
test/integration/test-app-main
command
|
|
|
test/scripttests
Package scripttests contains a specification of the behaviour of client-side scripting.
|
Package scripttests contains a specification of the behaviour of client-side scripting. |
|
testing/gomega-matchers
Package gomegamatchers just exposes gomega matchers for easier importing.
|
Package gomegamatchers just exposes gomega matchers for easier importing. |
|
testing/htmltest
Package htmltest contains test helpers when working with the html package
|
Package htmltest contains test helpers when working with the html package |
|
uievents
Package uievents creates and dispatches [UI Events].
|
Package uievents creates and dispatches [UI Events]. |
|
Package logger provides the basic functionality of supplying a custom logger.
|
Package logger provides the basic functionality of supplying a custom logger. |
|
scripting
|
|
|
gojahost
The gojahost package provides functionality to execute client-scripts in gost-dom.
|
The gojahost package provides functionality to execute client-scripts in gost-dom. |
|
internal/js
Package js provides an abstraction on top of V8.
|
Package js provides an abstraction on top of V8. |
|
internal/mathml
Package mathml implements (part of) the MathML-Core web API
|
Package mathml implements (part of) the MathML-Core web API |
|
v8host
The v8host packages provides functionality to execute client-side scripts in gost-dom.
|
The v8host packages provides functionality to execute client-side scripts in gost-dom. |
|
testing
|
|
|
gomega-matchers
Package matchers contains custom matches for use with the [Gomega] assertion library.
|
Package matchers contains custom matches for use with the [Gomega] assertion library. |
|
Package url contains types defined in the url web IDL spec.
|
Package url contains types defined in the url web IDL spec. |