Skip to content

Conversation

ankur22
Copy link
Contributor

@ankur22 ankur22 commented Aug 22, 2025

What?

Having looked at how Playwright works through adoption, I've realised that it only adopts when:

  1. the handle is from the current frame,
  2. and when the handle is in the utilityWorld.

I've made the change to ensure that adoption only occurs when the handle is part of the current frame's utilityWorld exec context.

Why?

While working on #5032, the current implementation is causing an issue whereby it is trying to adopt a handle from a nested frame to the page's frame (different origin), which isn't possible and is preventing APIs from working when using locators in iframes.

Adoption only works when adopting between mainWorld and utilityWorld from within the same frame. Each frame has these two execution contexts. We cannot adopt elements/handles from one frame to another, and there should be no reason to do so.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Linked to, but doesn't close: #5085

@ankur22 ankur22 added this to the v1.3.0 milestone Aug 22, 2025
@ankur22 ankur22 marked this pull request as ready for review August 22, 2025 14:13
@ankur22 ankur22 requested a review from a team as a code owner August 22, 2025 14:13
@ankur22 ankur22 requested review from codebien, inancgumus and joanlopez and removed request for a team August 22, 2025 14:13
Copy link
Contributor

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

🤞

Having looked at how Playwright works through adoption, I've realised
that it only adopts when the handle is from the current frame, and when
the handle is in the utility exec context. I've made the change to
ensure that adoption only occurs when the handle is part of the current
frame's utility exec context.
@ankur22 ankur22 force-pushed the fix/exec-context-adoption branch from 11db555 to cd3805b Compare August 26, 2025 15:11
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

Adoption only works when adopting between mainWorld and utilityWorld from within the same frame. Each frame has these two execution contexts. We cannot adopt elements/handles from one frame to another, and there should be no reason to do so.

@ankur22 If I understand correctly, before it was allowed to mix elements and frames which is not the case anymore with the new change. We should guard this logic with a unit test. Can you add a one, please?

@ankur22
Copy link
Contributor Author

ankur22 commented Sep 2, 2025

@ankur22 If I understand correctly, before it was allowed to mix elements and frames which is not the case anymore with the new change. We should guard this logic with a unit test. Can you add a one, please?

I'd love to be able to unit test this, but I think it would require a lot of refactoring. The changes in another PR (#5075) require the fix in this PR, and there is an integration test which will fail due to any regression.

@ankur22 ankur22 requested a review from codebien September 2, 2025 10:40
@ankur22 ankur22 merged commit 634240f into master Sep 2, 2025
37 checks passed
@ankur22 ankur22 deleted the fix/exec-context-adoption branch September 2, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider working with utility execution context on most operations

3 participants