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

Add browser close friendly err (#687) #803

Merged
merged 2 commits into from Mar 3, 2023

Conversation

inancgumus
Copy link
Member

@inancgumus inancgumus commented Mar 2, 2023

This PR does the following:

  • Allows executing Browser.Close only once.
  • Warns users with "a friendly message" when it's called multiple times.

Notes:

  • Close() is thread-safe as only the same VU or testBrowser use it.

You can try the result with this script:

import { chromium } from 'k6/x/browser';

export default async function () {
    const browser = chromium.launch();
    const page = browser.newPage();

    await page
        .goto('https://test.k6.io/', { waitUntil: 'networkidle' })
        .finally(() => {
            page.close();
            browser.close();
        });

    await page
        .goto('https://test.k6.io/contacts.php', { waitUntil: 'networkidle' })
        .finally(() => {
            page.close();
            browser.close();
        });
}

It should print:

WARN[0002] Please call browser.close only once, and do not use the browser after calling close.
  category="Browser:Close" elapsed="0 ms" goroutine=84

@inancgumus inancgumus force-pushed the add/687-browser-close-friendly-err branch from d3064d7 to 64ca112 Compare March 2, 2023 11:30
@inancgumus inancgumus marked this pull request as ready for review March 2, 2023 14:18
@inancgumus inancgumus requested review from ankur22 and ka3de March 2, 2023 14:18
@inancgumus inancgumus self-assigned this Mar 2, 2023
@inancgumus inancgumus linked an issue Mar 2, 2023 that may be closed by this pull request
@inancgumus inancgumus modified the milestone: v0.9.0 Mar 2, 2023
@inancgumus inancgumus added bug Something isn't working ux labels Mar 2, 2023
common/browser.go Outdated Show resolved Hide resolved
@inancgumus inancgumus requested a review from ka3de March 2, 2023 15:22
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on these optimizations!
LGTM.

Copy link
Collaborator

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@inancgumus inancgumus force-pushed the add/687-browser-close-friendly-err branch from 250b1e7 to d51fd9f Compare March 3, 2023 08:17
@inancgumus inancgumus merged commit 34e1ad0 into main Mar 3, 2023
@inancgumus inancgumus deleted the add/687-browser-close-friendly-err branch March 3, 2023 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display a friendly error when a browser is re-closed
3 participants