Skip to content

Commit

Permalink
Add a convenience method to get mainframe url
Browse files Browse the repository at this point in the history
This also protects the retrieval of the url with the mutex.
  • Loading branch information
ankur22 committed Sep 12, 2024
1 parent 6ec9b95 commit a5a7804
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions common/frame_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@ func (m *FrameManager) setMainFrame(f *Frame) {
m.mainFrame = f
}

// MainFrameURL returns the main frame's url.
func (m *FrameManager) MainFrameURL() string {
m.mainFrameMu.RLock()
defer m.mainFrameMu.RUnlock()

return m.mainFrame.URL()
}

// NavigateFrame will navigate specified frame to specified URL.
//
//nolint:funlen,cyclop
Expand Down
4 changes: 2 additions & 2 deletions common/frame_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (fs *FrameSession) initEvents() {
// because at the start of the span we don't know the correct url for
// the page we're navigating to. At the end of the span we do have this
// information.
fs.mainFrameSpan.SetAttributes(attribute.String("navigation.url", fs.manager.MainFrame().URL()))
fs.mainFrameSpan.SetAttributes(attribute.String("navigation.url", fs.manager.MainFrameURL()))
fs.mainFrameSpan.End()
fs.mainFrameSpan = nil
}
Expand Down Expand Up @@ -821,7 +821,7 @@ func (fs *FrameSession) processNavigationSpan(id cdp.FrameID) {
// because at the start of the span we don't know the correct url for
// the page we're navigating to. At the end of the span we do have this
// information.
fs.mainFrameSpan.SetAttributes(attribute.String("navigation.url", fs.manager.MainFrame().URL()))
fs.mainFrameSpan.SetAttributes(attribute.String("navigation.url", fs.manager.MainFrameURL()))
fs.mainFrameSpan.End()
}

Expand Down

0 comments on commit a5a7804

Please sign in to comment.