Fixing NavigateBack and NavigateForward implementation.
Removing entries loop to find current navigation entry, as GetNavigationHistory already returning index of current navigation history entry.
This commit is contained in:
parent
1988de618d
commit
786e242a24
26
nav.go
26
nav.go
|
@ -47,18 +47,11 @@ func NavigateBack(ctxt context.Context, h cdp.Handler) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var i int
|
if cur <= 0 || cur > int64(len(entries)-1) {
|
||||||
for ; i < len(entries); i++ {
|
return errors.New("invalid navigation entry")
|
||||||
if entries[i].ID == cur {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == 0 {
|
return page.NavigateToHistoryEntry(entries[cur-1].ID).Do(ctxt, h)
|
||||||
return errors.New("already on oldest navigation entry")
|
|
||||||
}
|
|
||||||
|
|
||||||
return page.NavigateToHistoryEntry(entries[i-1].ID).Do(ctxt, h)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NavigateForward navigates the current frame forwards in its history.
|
// NavigateForward navigates the current frame forwards in its history.
|
||||||
|
@ -68,18 +61,11 @@ func NavigateForward(ctxt context.Context, h cdp.Handler) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
i := len(entries) - 1
|
if cur < 0 || cur >= int64(len(entries)-1) {
|
||||||
for ; i > 0; i-- {
|
return errors.New("invalid navigation entry")
|
||||||
if entries[i].ID == cur {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == len(entries)-1 {
|
return page.NavigateToHistoryEntry(entries[cur+1].ID).Do(ctxt, h)
|
||||||
return errors.New("already on newest navigation entry")
|
|
||||||
}
|
|
||||||
|
|
||||||
return page.NavigateToHistoryEntry(entries[i+1].ID).Do(ctxt, h)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop stops all navigation and pending resource retrieval.
|
// Stop stops all navigation and pending resource retrieval.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user