@@ -1261,21 +1261,36 @@ func TestMain(m *testing.M) {
12611261}
12621262
12631263func checkNetworkRequests (t * testing.T , addr string ) {
1264- ctx , cancel := chromedp .NewContext (chromedpAllocator )
1264+ opts := append (chromedp .DefaultExecAllocatorOptions [:],
1265+ chromedp .Flag ("headless" , true ),
1266+ chromedp .Flag ("no-sandbox" , true ),
1267+ chromedp .Flag ("disable-gpu" , true ),
1268+ )
1269+ allocCtx , cancel := chromedp .NewExecAllocator (chromedpAllocator , opts ... )
1270+ defer cancel ()
1271+
1272+ ctx , cancel := chromedp .NewContext (allocCtx )
12651273 t .Cleanup (cancel )
12661274
1275+ // make sure browser is already started
1276+ err := chromedp .Run (ctx )
1277+ testutil .Ok (t , err )
1278+
12671279 testutil .Ok (t , runutil .Retry (1 * time .Minute , ctx .Done (), func () error {
12681280 var networkErrors []string
12691281
1282+ var newCtx context.Context
1283+ newCtx , newCancel := chromedp .NewContext (ctx )
1284+ t .Cleanup (newCancel )
12701285 // Listen for failed network requests and push them to an array.
1271- chromedp .ListenTarget (ctx , func (ev interface {}) {
1286+ chromedp .ListenTarget (newCtx , func (ev interface {}) {
12721287 switch ev := ev .(type ) {
12731288 case * network.EventLoadingFailed :
12741289 networkErrors = append (networkErrors , ev .ErrorText )
12751290 }
12761291 })
12771292
1278- err := chromedp .Run (ctx ,
1293+ err := chromedp .Run (newCtx ,
12791294 network .Enable (),
12801295 chromedp .Navigate (addr ),
12811296 chromedp .WaitVisible (`body` ),
0 commit comments