1234567891011121314151617181920212223 |
- package lxrod
- import (
- "github.com/go-rod/rod"
- "github.com/go-rod/rod/lib/proto"
- )
- // 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 WaitVuePageNavigated(p *rod.Page) NavigateResultFunc {
- var e proto.PageNavigatedWithinDocument
- wait := p.WaitEvent(&e)
- return func() (proto.PageNavigatedWithinDocument, bool) {
- wait()
- return e, e != proto.PageNavigatedWithinDocument{}
- }
- }
|