Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Desobekify BrowserContext.SetHTTPCredentials
  • Loading branch information
inancgumus committed Nov 4, 2024
commit a27ed33cd7f252f1a1770691303fc3f63ccf138f
10 changes: 7 additions & 3 deletions browser/browser_context_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
return nil, bc.SetGeolocation(gl)
}), nil
},
"setHTTPCredentials": func(httpCredentials sobek.Value) *sobek.Promise {
"setHTTPCredentials": func(httpCredentials sobek.Value) (*sobek.Promise, error) {
pc := common.NewCredentials()
if err := pc.Parse(vu.Context(), httpCredentials); err != nil {
return nil, fmt.Errorf("parsing HTTP credentials: %w", err)
}
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, bc.SetHTTPCredentials(httpCredentials) //nolint:staticcheck,wrapcheck
})
return nil, bc.SetHTTPCredentials(pc) //nolint:staticcheck
}), nil
},
"setOffline": func(offline bool) *sobek.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
Expand Down
10 changes: 2 additions & 8 deletions common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/chromedp/cdproto/network"
"github.com/chromedp/cdproto/storage"
"github.com/chromedp/cdproto/target"
"github.com/grafana/sobek"

"github.com/grafana/xk6-browser/common/js"
"github.com/grafana/xk6-browser/k6error"
Expand Down Expand Up @@ -312,17 +311,12 @@ func (b *BrowserContext) SetGeolocation(g *Geolocation) error {
// See for details:
// - https://github.com/microsoft/playwright/issues/2196#issuecomment-627134837
// - https://github.com/microsoft/playwright/pull/2763
func (b *BrowserContext) SetHTTPCredentials(httpCredentials sobek.Value) error {
func (b *BrowserContext) SetHTTPCredentials(hc *Credentials) error {
b.logger.Warnf("setHTTPCredentials", "setHTTPCredentials is deprecated."+
" Create a new BrowserContext with httpCredentials instead.")
b.logger.Debugf("BrowserContext:SetHTTPCredentials", "bctxid:%v", b.id)

c := NewCredentials()
if err := c.Parse(b.ctx, httpCredentials); err != nil {
return fmt.Errorf("parsing HTTP credentials: %w", err)
}

b.opts.HttpCredentials = c
b.opts.HttpCredentials = hc
for _, p := range b.browser.getPages() {
if err := p.updateHTTPCredentials(); err != nil {
return fmt.Errorf("setting HTTP credentials in target ID %s: %w", p.targetID, err)
Expand Down