Skip to content

Commit 267470d

Browse files
committed
deprecate: Consistent browser construction
Indicate that browser.NewFromHandler should not be used, preferring New(WithHandler()) instead.
1 parent a12314e commit 267470d

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

browser.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ type browserConfig struct {
2020
type BrowserOption func(*browserConfig)
2121

2222
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.
2335
func WithHandler(h http.Handler) BrowserOption {
2436
return func(b *browserConfig) { b.client = NewHttpClientFromHandler(h) }
2537
}
@@ -60,22 +72,11 @@ func (b *Browser) Open(location string) (window Window, err error) {
6072
return
6173
}
6274

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]
6676
//
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.
7478
func NewFromHandler(handler http.Handler) *Browser {
75-
return &Browser{
76-
ScriptHost: v8host.New(),
77-
Client: NewHttpClientFromHandler(handler),
78-
}
79+
return New(WithHandler(handler))
7980
}
8081

8182
// New initialises a new [Browser] with the default script engine.

0 commit comments

Comments
 (0)