This example connects to a hosted browser service that needs an Authorization header on the websocket request.
()
| 101 | // This example connects to a hosted browser service that needs an |
| 102 | // Authorization header on the websocket request. |
| 103 | func ExampleWithDialHTTPHeader() { |
| 104 | const wsURL = "wss://browser.example.com/devtools/browser/id" |
| 105 | header := http.Header{"Authorization": {"Bearer " + os.Getenv("BROWSER_TOKEN")}} |
| 106 | |
| 107 | allocCtx, cancel := remote.NewAllocator(context.Background(), wsURL, |
| 108 | remote.NoModifyURL, |
| 109 | remote.WithDialHTTPHeader(header), |
| 110 | ) |
| 111 | defer cancel() |
| 112 | ctx, cancel := chromedp.NewContext(allocCtx) |
| 113 | defer cancel() |
| 114 | |
| 115 | title, err := chromedp.Run(ctx, chromedp.Title()) |
| 116 | if err != nil { |
| 117 | log.Fatal(err) |
| 118 | } |
| 119 | fmt.Println(title) |
| 120 | } |
nothing calls this directly
no test coverage detected