Merge pull request 'fix: address Playwright API audit findings' (#83) from fix/playwright-api-audit into main
Reviewed-on: #83
This commit was merged in pull request #83.
This commit is contained in:
@@ -95,6 +95,9 @@ func NewInteractiveBrowser(ctx context.Context, opts ...BrowserOptions) (Interac
|
|||||||
|
|
||||||
page, err := res.bctx.NewPage()
|
page, err := res.bctx.NewPage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = res.bctx.Close()
|
||||||
|
_ = res.browser.Close()
|
||||||
|
_ = res.pw.Stop()
|
||||||
ch <- result{nil, fmt.Errorf("failed to create page: %w", err)}
|
ch <- result{nil, fmt.Errorf("failed to create page: %w", err)}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -112,6 +115,12 @@ func NewInteractiveBrowser(ctx context.Context, opts ...BrowserOptions) (Interac
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
go func() {
|
||||||
|
r := <-ch
|
||||||
|
if r.err == nil && r.ib != nil {
|
||||||
|
_ = r.ib.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
case r := <-ch:
|
case r := <-ch:
|
||||||
return r.ib, r.err
|
return r.ib, r.err
|
||||||
|
|||||||
2
node.go
2
node.go
@@ -29,7 +29,7 @@ type node struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n node) Type(input string) error {
|
func (n node) Type(input string) error {
|
||||||
return n.locator.Type(input)
|
return n.locator.PressSequentially(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n node) Click() error {
|
func (n node) Click() error {
|
||||||
|
|||||||
@@ -195,6 +195,12 @@ func NewBrowser(ctx context.Context, opts ...BrowserOptions) (Browser, error) {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
go func() {
|
||||||
|
r := <-resultCh
|
||||||
|
if r.err == nil && r.browser != nil {
|
||||||
|
_ = r.browser.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
case result := <-resultCh:
|
case result := <-resultCh:
|
||||||
return result.browser, result.err
|
return result.browser, result.err
|
||||||
@@ -242,6 +248,7 @@ func (b playWrightBrowser) openPage(_ context.Context, target string, opts OpenP
|
|||||||
|
|
||||||
resp, err := page.Goto(target, pwOpts)
|
resp, err := page.Goto(target, pwOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = page.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,8 +284,8 @@ func (b playWrightBrowser) Open(ctx context.Context, url string, opts OpenPageOp
|
|||||||
|
|
||||||
func (b playWrightBrowser) Close() error {
|
func (b playWrightBrowser) Close() error {
|
||||||
return errors.Join(
|
return errors.Join(
|
||||||
b.browser.Close(),
|
|
||||||
b.ctx.Close(),
|
b.ctx.Close(),
|
||||||
|
b.browser.Close(),
|
||||||
b.pw.Stop(),
|
b.pw.Stop(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user