|
| 1 | +// Package browser provides an entry point to the browser extension. |
1 | 2 | package browser
|
2 | 3 |
|
3 | 4 | import (
|
4 | 5 | "log"
|
5 | 6 | "net/http"
|
6 |
| - _ "net/http/pprof" // nolint:gosec |
| 7 | + _ "net/http/pprof" //nolint:gosec |
7 | 8 | "os"
|
8 | 9 |
|
9 |
| - "github.com/grafana/xk6-browser/api" |
10 |
| - "github.com/grafana/xk6-browser/chromium" |
11 |
| - "github.com/grafana/xk6-browser/common" |
| 10 | + "github.com/grafana/xk6-browser/browser" |
12 | 11 |
|
13 | 12 | k6modules "go.k6.io/k6/js/modules"
|
14 | 13 | )
|
15 | 14 |
|
16 |
| -const version = "0.6.0" |
17 |
| - |
18 |
| -type ( |
19 |
| - // RootModule is the global module instance that will create module |
20 |
| - // instances for each VU. |
21 |
| - RootModule struct{} |
22 |
| - |
23 |
| - // JSModule exposes the properties available to the JS script. |
24 |
| - JSModule struct { |
25 |
| - Chromium api.BrowserType |
26 |
| - Devices map[string]common.Device |
27 |
| - Version string |
28 |
| - } |
29 |
| - |
30 |
| - // ModuleInstance represents an instance of the JS module. |
31 |
| - ModuleInstance struct { |
32 |
| - mod *JSModule |
33 |
| - } |
34 |
| -) |
35 |
| - |
36 |
| -var ( |
37 |
| - _ k6modules.Module = &RootModule{} |
38 |
| - _ k6modules.Instance = &ModuleInstance{} |
39 |
| -) |
40 |
| - |
41 | 15 | func init() {
|
42 | 16 | if _, ok := os.LookupEnv("K6_BROWSER_PPROF"); ok {
|
43 | 17 | go func() {
|
44 | 18 | address := "localhost:6060"
|
45 | 19 | log.Println("Starting http debug server", address)
|
46 |
| - log.Println(http.ListenAndServe(address, nil)) |
| 20 | + log.Println(http.ListenAndServe(address, nil)) //nolint:gosec |
| 21 | + // no linted because we don't need to set timeouts for the debug server. |
47 | 22 | }()
|
48 | 23 | }
|
49 | 24 | }
|
50 | 25 |
|
51 |
| -// New returns a pointer to a new RootModule instance. |
52 |
| -func New() *RootModule { |
53 |
| - return &RootModule{} |
54 |
| -} |
55 |
| - |
56 |
| -// NewModuleInstance implements the k6modules.Module interface to return |
57 |
| -// a new instance for each VU. |
58 |
| -func (*RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance { |
59 |
| - return &ModuleInstance{ |
60 |
| - mod: &JSModule{ |
61 |
| - Chromium: chromium.NewBrowserType(vu), |
62 |
| - Devices: common.GetDevices(), |
63 |
| - Version: version, |
64 |
| - }, |
65 |
| - } |
66 |
| -} |
67 |
| - |
68 |
| -// Exports returns the exports of the JS module so that it can be used in test |
69 |
| -// scripts. |
70 |
| -func (mi *ModuleInstance) Exports() k6modules.Exports { |
71 |
| - return k6modules.Exports{Default: mi.mod} |
72 |
| -} |
73 |
| - |
74 | 26 | func init() {
|
75 |
| - k6modules.Register("k6/x/browser", New()) |
| 27 | + k6modules.Register("k6/x/browser", browser.New()) |
76 | 28 | }
|
0 commit comments