MCPcopy Create free account
hub / github.com/chromedp/chromedp / ExampleWithDialHTTPHeader

Function ExampleWithDialHTTPHeader

remote/example_test.go:103–120  ·  view source on GitHub ↗

This example connects to a hosted browser service that needs an Authorization header on the websocket request.

()

Source from the content-addressed store, hash-verified

101// This example connects to a hosted browser service that needs an
102// Authorization header on the websocket request.
103func 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}

Callers

nothing calls this directly

Calls 5

NewAllocatorFunction · 0.92
WithDialHTTPHeaderFunction · 0.92
NewContextFunction · 0.92
RunFunction · 0.92
TitleFunction · 0.92

Tested by

no test coverage detected