chromedp / chromedp

A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to execute simultaneously

txf1p opened this issue · comments

func (s *session) SendMessage(_ context.Context) {
	var wg sync.WaitGroup
	for n, _ := range numbers {
		wg.Add(1)
		go func(n string) {
			defer wg.Done()
			flag := true
			ctx, cancel := chromedp.NewContext(s.ctx)
			defer cancel()
			if err := chromedp.Run(
				ctx,
				....................
			); err != nil {
				flag = false
			}
		}(n)
	}
	wg.Wait()
	return
}

s.ctx has completed the login. Now I want each coroutine to perform the same operation (open many new windows for execution),

Opening the current code will cause the newly opened page to be about:blank. If you use s.ctx directly, you will operate on the same page.