Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable multiple k6-browser instances to run concurrent tests against a single browser #848

Merged
merged 17 commits into from
Apr 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ func (b *Browser) onAttachedToTarget(ev *target.EventAttachedToTarget) {
}
}

// attachNewPage registers the page as an active page and attaches the sessionID with the targetID.
func (b *Browser) attachNewPage(p *Page, ev *target.EventAttachedToTarget) {
targetPage := ev.TargetInfo

// Register the page as an active page.
b.pagesMu.Lock()
b.logger.Debugf("Browser:onAttachedToTarget:addTarget", "sid:%v tid:%v pageType:%s",
inancgumus marked this conversation as resolved.
Show resolved Hide resolved
ev.SessionID, targetPage.TargetID, targetPage.Type)
b.pages[targetPage.TargetID] = p
b.pagesMu.Unlock()

// Attach the sessionID with the targetID so we can communicate with the
// page later.
b.sessionIDtoTargetIDMu.Lock()
b.logger.Debugf("Browser:onAttachedToTarget:addSession", "sid:%v tid:%v pageType:%s",
ev.SessionID, targetPage.TargetID, targetPage.Type)
b.sessionIDtoTargetID[ev.SessionID] = targetPage.TargetID
b.sessionIDtoTargetIDMu.Unlock()
}

// isAttachedPageValid returns true if the attached page is valid and should be
// added to the browser's pages. It returns false if the attached page is not
// valid and should be ignored.
Expand Down