Skip to content

Add a method to wait vue page navigated. #1166

Open
@kvii

Description

@kvii

Rod Version: v0.116.2

demo 如下:

// vue 页面导航完成结果。如果提前停止等待则返回 false。
type NavigateResultFunc = func() (proto.PageNavigatedWithinDocument, bool)

// 等待 vue hash 路由页面导航完成。
// vue router 有一个 hash 模式。页面的 url 会变成 xx.com/#/yy 的格式。
// 此时页面的“跳转”是用 url 的 fragment 模拟的,并不会触发真正的页面导航。
// 该函数会等待这种页面的跳转事件,并且返回导航的信息。如果监听提前停止则会返回 false。
// 可以给 p 的 ctx 添加 timeout 或者 cancel 来达到提前停止的目的。
func (p *rod.Page) WaitVuePageNavigated() NavigateResultFunc {
	var e proto.PageNavigatedWithinDocument
	wait := p.WaitEvent(&e)
	return func() (proto.PageNavigatedWithinDocument, bool) {
		wait()
		return e, e != proto.PageNavigatedWithinDocument{}
	}
}

当然相关的命名应该改一下。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhanceNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions