@@ -20,6 +20,18 @@ type browserConfig struct {
20
20
type BrowserOption func (* browserConfig )
21
21
22
22
func WithLogger (l * slog.Logger ) BrowserOption { return func (b * browserConfig ) { b .logger = l } }
23
+
24
+ // WithHandler configures the browser's [http.Client] to use an
25
+ // [http.Roundtripper] that bypasses the TCP stack and calls directly into the
26
+ // specified handler as a normal function call.
27
+ //
28
+ // Note: There is a current limitation that NO requests from the browser will be
29
+ // sent when using this. So sites will not work if they
30
+ // - Depend on content from CDN
31
+ // - Depend on an external service, e.g., an identity provider.
32
+ //
33
+ // That is a limitation that was the result of prioritising more important, and
34
+ // higher risk features.
23
35
func WithHandler (h http.Handler ) BrowserOption {
24
36
return func (b * browserConfig ) { b .client = NewHttpClientFromHandler (h ) }
25
37
}
@@ -60,22 +72,11 @@ func (b *Browser) Open(location string) (window Window, err error) {
60
72
return
61
73
}
62
74
63
- // NewFromHandler initialises a new [Browser] with the default script engine and
64
- // sets up the internal [http.Client] used with an [http.Roundtripper] that
65
- // bypasses the TCP stack and calls directly into the
75
+ // NewFromHandler initialises a new [Browser] with with an [http.Handler]
66
76
//
67
- // Note: There is a current limitation that NO requests from the browser will be
68
- // sent when using this. So sites will not work if they
69
- // - Depend on content from CDN
70
- // - Depend on an external service, e.g., an identity provider.
71
- //
72
- // That is a limitation that was the result of prioritising more important, and
73
- // higher risk features.
77
+ // Deprecated: Prefer browser.New(browser.WithHandler(...)) instead.
74
78
func NewFromHandler (handler http.Handler ) * Browser {
75
- return & Browser {
76
- ScriptHost : v8host .New (),
77
- Client : NewHttpClientFromHandler (handler ),
78
- }
79
+ return New (WithHandler (handler ))
79
80
}
80
81
81
82
// New initialises a new [Browser] with the default script engine.
0 commit comments