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

Commit cecafd3

Browse files
committed
Add locks to Frame properties
There were data races after adding logs because several entities were accessing Frame properties concurrently.
1 parent 90d971a commit cecafd3

File tree

5 files changed

+141
-83
lines changed

5 files changed

+141
-83
lines changed

common/browser_context.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
cdpbrowser "github.com/chromedp/cdproto/browser"
3030
"github.com/chromedp/cdproto/cdp"
3131
"github.com/chromedp/cdproto/storage"
32+
"github.com/chromedp/cdproto/target"
3233
"github.com/dop251/goja"
3334
"github.com/grafana/xk6-browser/api"
3435
k6common "go.k6.io/k6/js/common"
@@ -220,7 +221,19 @@ func (b *BrowserContext) NewPage() api.Page {
220221
if err != nil {
221222
k6Throw(b.ctx, "cannot create a new page: %w", err)
222223
}
223-
b.logger.Debugf("BrowserContext:NewPage:return", "bctxid:%v ptid:%s", b.id, p.targetID)
224+
225+
var (
226+
bctxid cdp.BrowserContextID
227+
ptid target.ID
228+
)
229+
if b != nil {
230+
bctxid = b.id
231+
}
232+
if p != nil {
233+
ptid = p.targetID
234+
}
235+
b.logger.Debugf("BrowserContext:NewPage:return", "bctxid:%v ptid:%s", bctxid, ptid)
236+
224237
return p
225238
}
226239

common/execution_context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func NewExecutionContext(
7373
e.stid = cdp.FrameID(session.targetID)
7474
}
7575
if frame != nil {
76-
e.fid = frame.id
77-
e.furl = frame.url
76+
e.fid = cdp.FrameID(frame.ID())
77+
e.furl = frame.URL()
7878
}
7979
logger.Debugf(
8080
"NewExecutionContext",
@@ -114,7 +114,7 @@ func (e *ExecutionContext) adoptElementHandle(eh *ElementHandle) (*ElementHandle
114114
esid target.SessionID
115115
)
116116
if eh.frame != nil {
117-
efid = eh.frame.id
117+
efid = cdp.FrameID(eh.frame.ID())
118118
}
119119
if eh.session != nil {
120120
esid = eh.session.id

0 commit comments

Comments
 (0)