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

page.StopLoading() cannot stop navigate #1450

Open
chenbyby opened this issue Mar 20, 2024 · 0 comments
Open

page.StopLoading() cannot stop navigate #1450

chenbyby opened this issue Mar 20, 2024 · 0 comments

Comments

@chenbyby
Copy link

What versions are you running?

$ go list -m github.com/chromedp/chromedp
github.com/chromedp/chromedp v0.9.5

$ chromedriver --version
on mac
ChromeDriver 112.0.5615.49 (bd2a7bcb881c11e8cfe3078709382934e3916914-refs/branch-heads/5615@{#936})

$ google-chrome --version
on linux
Google Chrome 122.0.6261.94

$ go version
go version go1.20.5 darwin/amd64

What did you do? Include clear steps.

1. Run the code below, use page.StopLoading(), the process still hangup
package main

import (
	"context"
	"fmt"

	"log"
	"time"

	"github.com/chromedp/cdproto/emulation"
	"github.com/chromedp/cdproto/network"
	"github.com/chromedp/cdproto/page"
	"github.com/chromedp/chromedp"
)

func main() {
	opts := append(chromedp.DefaultExecAllocatorOptions[:],
		chromedp.Flag("headless", false),
	)

	allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
	defer cancel()

	ctx, cancel := chromedp.NewContext(allocCtx)
	defer cancel()

	go func() {
		time.Sleep(time.Second * 3)
		err := chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error {
			_, _ = emulation.SetVirtualTimePolicy(emulation.VirtualTimePolicyPause).Do(ctx)
			return page.StopLoading().Do(ctx)
		}))
		fmt.Println(err)
	}()

	fmt.Println("Start running")

	err := chromedp.Run(ctx,
		network.SetBlockedURLS([]string{"*.jpg", "*.png", "*.gif", "*.jpeg", "*.webp", "*.svg"}),
		chromedp.Navigate("http://www.ccydia.cn"),
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("End running =====>")
}
  • and the phenomenon show like this
the browser hangup
2. If I remove the line network.SetBlockedURLS and use the fix acfasj@2a541a5

it will work fine

What did you expect to see?

  • The process exit, no hangup, can see End running =====> in console

What did you see instead?

  • The process hangup, never stop
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

No branches or pull requests

1 participant