Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to NewRemoteAllocator to avoid URL detection #990

Closed
wants to merge 1 commit into from

Conversation

andyMrtnzP
Copy link

Summary

This PR solves issue #972. RemoteAllocatorOption was added, which contains FetchJSONDebuggerURL. This could avoid URL detection on NewRemoteAllocator. PersistDebuggerURL, an instance of RemoteAllocatorOption was added, with FetchJSONDebuggerURL as false.

Example

Consider connecting to a wss:// URL

func main() {
  var devToolWsUrl string
  var title string
  var opts = chromedp.PersistDebuggerURL
  var url = "wss://chrome.browserless.io?token=my_token_here"

  flag.StringVar(&devToolWsUrl, "devtools-ws-url", url, "DevTools Websocket URL")
  flag.Parse()

  actxt, cancelActxt := chromedp.NewRemoteAllocator(context.Background(), devToolWsUrl, opts)
  // works as well      chromedp.NewRemoteAllocator(context.Background(), devToolWsUrl, chromedp.RemoteAllocatorOption{ FetchJSONDebuggerURL: false })
  defer cancelActxt()

  ctxt, cancelCtxt := chromedp.NewContext(actxt) // create new tab
  defer cancelCtxt()                             // close tab afterwards

  if err := chromedp.Run(ctxt,
    chromedp.Navigate("https://example.com"),
    chromedp.Title(&title),
  ); err != nil {
    log.Fatalf("Failed getting title of example.com: %v", err)
  }

  log.Println("Got title: `" + title + "`")
}

will connect to the WebSocket and scrape the page correctly -- it currently does not connect and errs a HTTP 301

@@ -524,6 +533,12 @@ type RemoteAllocator struct {
wg sync.WaitGroup
}

type RemoteAllocatorOption struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should stick with the functional options pattern. Refer to how ExecAllocatorOption is implemented.

@ZekeLu
Copy link
Member

ZekeLu commented Oct 31, 2022

Closing in favor of #1184. Thank you!

@ZekeLu ZekeLu closed this Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants