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

Browser v2: Async APIs #428

Closed
23 tasks done
Tracked by #1117
sniku opened this issue Jun 30, 2022 · 3 comments
Closed
23 tasks done
Tracked by #1117

Browser v2: Async APIs #428

sniku opened this issue Jun 30, 2022 · 3 comments
Assignees
Labels
async supports async (promises) epic feature A new feature playwright Issue relating to Playwright compatibility

Comments

@sniku
Copy link
Collaborator

sniku commented Jun 30, 2022

Migrate to Async

No tasks being tracked yet.

Nice to have

  1. 4 of 4
    documentation-needed enhancement
    allansson

Migration is complete - Document the changes

No tasks being tracked yet.

Done Done

  1. 10 of 10
    async
    inancgumus
  2. 7 of 7
    async breaking
    inancgumus
  3. async compatibility dx epic mapping next refactor
    inancgumus
  4. async enhancement refactor tests
    inancgumus
  5. async feature
    inancgumus
  6. async feature
    ankur22 inancgumus
  7. 5 of 5
    async breaking
    inancgumus
  8. 7 of 7
    async breaking
    inancgumus
  9. 6 of 6
    async breaking browser context
    inancgumus
  10. 7 of 7
    async breaking
    inancgumus
  11. 5 of 5
    async breaking
    ankur22 inancgumus
  12. 6 of 6
    async breaking
    inancgumus
  13. 7 of 7
    async breaking
    inancgumus
  14. 6 of 6
    async breaking
    inancgumus
  15. 9 of 9
    async breaking
    inancgumus
  16. 9 of 9
    async breaking
    ankur22
  17. 4 of 4
    async breaking
    ankur22 inancgumus
  18. 3 of 3
    enhancement
    inancgumus
  19. async productivity refactor tests
    inancgumus
  20. async refactor
    inancgumus
  21. 2 of 2
    Area: browser
    ankur22

What

This issue has been repurposed to initiate and follow the progress of migrating most of the browser APIs to async (promise based).

A recent example is this issue where touchscreen.tap was migrated to async:

From:

page.touchscreen.tap(...);

To:

await page.touchscreen.tap(...);

Why

  1. Most browser APIs use some form of long-running IO operation (networking) to perform the requested action on the web browser against the website under test. We need to avoid blocking JavaScript's runtime event loop for such operations.
  2. We're going to add more asynchronous event-based APIs (such as page.on) that our current synchronous APIs would block.
  3. To align with how developers expect to work with JavaScript APIs.
  4. To have better compatibility with Playwright.

How

We have detailed exactly which APIs will most likely need to be migrated across in the comment within this issue. For most of the APIs we can take a look at the comment and migrate the APIs that are listed there. It's worth noting that it's still best to double check whether the API needs to be migrated especially ones which k6 browser implements but aren't provided by Playwright, for example page.throttleCPU.

NOT Implemented In PW

If an API is not implemented in PW, then you should be able to answer yes to one of the questions in the list below to determine whether it should be async or not, for example browser.context is not in PW, and it doesn't do any IO or long running tasks, therefore it can stay as a synchronous API.

  1. Does the API perform a network call or other IO operations, this includes a CDP request to Chrome?
  2. Does the API perform long running task?

Implemented in PW

Is the API in the list in this comment and is implemented in PW?

If the answer is yes, then it can be migrated to async.

Goja, docs and type defs

Initially we're only interested in moving the API to async, and not worrying about goja, doc and type definitions updates. Doc and type definition updates will be deferred to after the implementation work and before the release. We're hoping that the goja refactoring/abstraction work can also be shifted to a later point, but we may find that some APIs will also need goja to be refactored out of them to prevent panics and race conditions.

@sniku sniku changed the title Async APIs Async APIs (placeholder) Jun 30, 2022
@sniku sniku added this to the v0.5.0 milestone Jun 30, 2022
@inancgumus inancgumus added feature A new feature playwright Issue relating to Playwright compatibility next Might be eligible for the next planning (not guaranteed!) labels Jul 4, 2022
@inancgumus inancgumus changed the title Async APIs (placeholder) Async APIs Support Jul 4, 2022
@inancgumus inancgumus changed the title Async APIs Support Async APIs Jul 4, 2022
@inancgumus inancgumus modified the milestones: v0.5.0, v0.6.0 Jul 19, 2022
@mstoykov mstoykov self-assigned this Oct 11, 2022
mstoykov added a commit that referenced this issue Oct 12, 2022
@mstoykov mstoykov mentioned this issue Oct 12, 2022
mstoykov added a commit that referenced this issue Oct 12, 2022
mstoykov added a commit that referenced this issue Oct 12, 2022
mstoykov added a commit that referenced this issue Oct 13, 2022
Updates #428

Co-authored-by: Ivan Mirić <ivan.miric@grafana.com>
mstoykov added a commit that referenced this issue Oct 13, 2022
@inancgumus inancgumus removed this from the v0.6.0 milestone Nov 7, 2022
@inancgumus inancgumus added async supports async (promises) and removed evaluate labels Jan 10, 2023
@inancgumus inancgumus removed their assignment Apr 10, 2023
@inancgumus inancgumus removed the next Might be eligible for the next planning (not guaranteed!) label Sep 22, 2023
@ankur22
Copy link
Collaborator

ankur22 commented May 31, 2024

It's worth noting that the browser module already has APIs (as of v0.51.0) that are already async:

  • browserContext.waitForevent
  • elementHandle.click
  • elementHandle.tap
  • frame.click
  • frame.goto
  • frame.tap
  • frame.waitForFunction
  • frame.waitForNavigation
  • locator.click
  • locator.tap
  • page.click
  • page.goto
  • page.tap
  • page.waitForFunction
  • page.waitForNavigation

Even though we have these, the changes we are making will still affect all users and their scripts since APIs such as browser.newPage are required for all browser tests.

@ankur22
Copy link
Collaborator

ankur22 commented May 31, 2024

Showcasing what to to expect when migrating your sync script to async with the fillform.js example:

NOTE: The changes required to work with check. Just like group, check doesn't work with async APIs.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async supports async (promises) epic feature A new feature playwright Issue relating to Playwright compatibility
Projects
None yet
Development

No branches or pull requests

5 participants