Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit eae4720

Browse files
authored
Merge pull request #178 from grafana/fix/177-frameAbortedNavigation-nil-pendingDocument
2 parents 799fbf2 + a1d813a commit eae4720

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

common/frame_manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,19 @@ func (m *FrameManager) frameAbortedNavigation(frameID cdp.FrameID, errorText, do
137137
if documentID != "" && frame.pendingDocument.documentID != documentID {
138138
return
139139
}
140-
frame.pendingDocument = nil
141140

142141
m.logger.Debugf("FrameManager:frameAbortedNavigation:emit:EventFrameNavigation",
143142
"fmid:%d fid:%v err:%s docid:%s fname:%s furl:%s",
144143
m.ID(), frameID, errorText, documentID, frame.Name(), frame.URL())
145144

146-
frame.emit(EventFrameNavigation, &NavigationEvent{
145+
ne := &NavigationEvent{
147146
url: frame.URL(),
148147
name: frame.Name(),
149148
newDocument: frame.pendingDocument,
150149
err: errors.New(errorText),
151-
})
150+
}
151+
frame.pendingDocument = nil
152+
frame.emit(EventFrameNavigation, ne)
152153
}
153154

154155
func (m *FrameManager) frameAttached(frameID cdp.FrameID, parentFrameID cdp.FrameID) {

common/frame_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
// Test calling Frame.document does not panic with a nil document.
34-
// See: issue #53 for details.
34+
// See: Issue #53 for details.
3535
func TestFrameNilDocument(t *testing.T) {
3636
t.Parallel()
3737

@@ -80,6 +80,40 @@ func TestFrameNilDocument(t *testing.T) {
8080
require.Equal(t, want, got)
8181
}
8282

83+
// See: Issue #177 for details.
84+
func TestFrameManagerFrameAbortedNavigationShouldEmitANonNilPendingDocument(t *testing.T) {
85+
t.Parallel()
86+
87+
ctx, log := context.Background(), NewNullLogger()
88+
89+
// add the frame to frame manager
90+
fm := NewFrameManager(ctx, nil, nil, NewTimeoutSettings(nil), log)
91+
frame := NewFrame(ctx, fm, nil, cdp.FrameID("42"), log)
92+
fm.frames[frame.id] = frame
93+
94+
// listen for frame navigation events
95+
recv := make(chan Event)
96+
frame.on(ctx, []string{EventFrameNavigation}, recv)
97+
98+
// emit the navigation event
99+
frame.pendingDocument = &DocumentInfo{
100+
documentID: "42",
101+
}
102+
fm.frameAbortedNavigation(frame.id, "any error", frame.pendingDocument.documentID)
103+
104+
// receive the emitted event and verify that emitted document
105+
// is not nil.
106+
e := <-recv
107+
require.IsType(t, &NavigationEvent{}, e.data, "event should be a navigation event")
108+
ne := e.data.(*NavigationEvent)
109+
require.NotNil(t, ne, "event should not be nil")
110+
require.NotNil(t, ne.newDocument, "emitted document should not be nil")
111+
112+
// since the navigation is aborted, the aborting frame should have
113+
// a nil pending document.
114+
require.Nil(t, frame.pendingDocument)
115+
}
116+
83117
type executionContextTestStub struct {
84118
ExecutionContext
85119
evaluateFn func(apiCtx context.Context, opts evaluateOptions, pageFunc goja.Value, args ...goja.Value) (res interface{}, err error)

0 commit comments

Comments
 (0)