@@ -3,6 +3,7 @@ package html
3
3
import (
4
4
"errors"
5
5
"io"
6
+ "log/slog"
6
7
"net/http"
7
8
netURL "net/url"
8
9
"strings"
@@ -27,6 +28,7 @@ type Clock interface {
27
28
28
29
// Describes a current browsering context
29
30
type BrowsingContext interface {
31
+ log.LogSource
30
32
HTTPClient () http.Client
31
33
LocationHREF () string
32
34
}
@@ -76,6 +78,7 @@ type window struct {
76
78
httpClient http.Client
77
79
baseLocation string
78
80
domParser domParser
81
+ logger * slog.Logger
79
82
}
80
83
81
84
func newWindow (windowOptions ... WindowOption ) * window {
@@ -88,6 +91,7 @@ func newWindow(windowOptions ...WindowOption) *window {
88
91
httpClient : options .HttpClient ,
89
92
baseLocation : options .BaseLocation ,
90
93
scriptEngineFactory : options .ScriptHost ,
94
+ logger : options .Logger ,
91
95
history : new (History ),
92
96
}
93
97
if win .baseLocation == "" {
@@ -193,20 +197,6 @@ func (w *window) parseReader(reader io.Reader) error {
193
197
194
198
func (w * window ) HTTPClient () http.Client { return w .httpClient }
195
199
196
- type WindowOptions struct {
197
- ScriptHost
198
- HttpClient http.Client
199
- BaseLocation string
200
- }
201
-
202
- type WindowOption interface {
203
- Apply (options * WindowOptions )
204
- }
205
-
206
- type WindowOptionFunc func (* WindowOptions )
207
-
208
- func (f WindowOptionFunc ) Apply (options * WindowOptions ) { f (options ) }
209
-
210
200
func WindowOptionLocation (location string ) WindowOptionFunc {
211
201
return func (options * WindowOptions ) {
212
202
options .BaseLocation = location
@@ -234,7 +224,7 @@ func (w *window) handleResponse(resp *http.Response) error {
234
224
}
235
225
236
226
func (w * window ) Navigate (href string ) error {
237
- log .Info ("Window.navigate:" , "href" , href )
227
+ log .Info (w . Logger (), "Window.navigate:" , "href" , href )
238
228
w .History ().pushLoad (href )
239
229
w .initScriptEngine ()
240
230
w .baseLocation = href
@@ -253,7 +243,7 @@ func (w *window) Navigate(href string) error {
253
243
// reload is used internally to load a page into the browser, but without
254
244
// affecting the history
255
245
func (w * window ) reload (href string ) error {
256
- log .Debug ("Window.reload:" , "href" , href )
246
+ log .Debug (w . Logger (), "Window.reload:" , "href" , href )
257
247
w .initScriptEngine ()
258
248
w .baseLocation = href
259
249
if href == "about:blank" {
@@ -327,3 +317,20 @@ func (w *window) resolveHref(href string) *url.URL {
327
317
}
328
318
return r
329
319
}
320
+
321
+ func (w * window ) Logger () log.Logger { return w .logger }
322
+
323
+ type WindowOptions struct {
324
+ ScriptHost
325
+ HttpClient http.Client
326
+ BaseLocation string
327
+ Logger * slog.Logger
328
+ }
329
+
330
+ type WindowOption interface {
331
+ Apply (options * WindowOptions )
332
+ }
333
+
334
+ type WindowOptionFunc func (* WindowOptions )
335
+
336
+ func (f WindowOptionFunc ) Apply (options * WindowOptions ) { f (options ) }
0 commit comments