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

Limit browser implementation to hold a single browserContext #929

Merged
merged 6 commits into from
Jun 14, 2023
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
Apply suggestions from code review
Co-authored-by: ka3de <[email protected]>
  • Loading branch information
ankur22 and ka3de committed Jun 13, 2023
commit 626d4bea54b1ed41bbdfa3e8c951e693393a0a14
2 changes: 1 addition & 1 deletion common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (b *Browser) IsConnected() bool {
// NewContext creates a new incognito-like browser context.
func (b *Browser) NewContext(opts goja.Value) (api.BrowserContext, error) {
if b.context != nil {
return nil, errors.New("close the existing browser context before creating a new one")
return nil, errors.New("existing browser context must be closed before creating a new one")
}

action := target.CreateBrowserContext().WithDisposeOnDetach(true)
Expand Down
6 changes: 3 additions & 3 deletions tests/browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func TestBrowserNewPage(t *testing.T) {
assert.Equal(t, 1, l, "expected there to be 1 browser context, but found %d", l)

_, err := b.Browser.NewPage(nil)
assert.EqualError(t, err, "new page: close the existing browser context before creating a new one")
assert.EqualError(t, err, "new page: existing browser context must be closed before creating a new one")

err = p1.Close(nil)
require.NoError(t, err)
l = len(b.Contexts())
assert.Equal(t, 1, l, "expected there to be 1 browser context, but found %d", l)

_, err = b.Browser.NewPage(nil)
assert.EqualError(t, err, "new page: close the existing browser context before creating a new one")
assert.EqualError(t, err, "new page: existing browser context must be closed before creating a new one")

b.Contexts()[0].Close()
l = len(b.Contexts())
Expand All @@ -54,7 +54,7 @@ func TestBrowserNewContext(t *testing.T) {
assert.Equal(t, 1, l, "expected there to be 1 browser context, but found %d", l)

_, err = b.NewContext(nil)
assert.EqualError(t, err, "close the existing browser context before creating a new one")
assert.EqualError(t, err, "existing browser context must be closed before creating a new one")

bc1.Close()
l = len(b.Contexts())
Expand Down