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

Investigate whether it's possible to skip page creation when browserContext is not found #933

Open
ankur22 opened this issue Jun 13, 2023 · 0 comments

Comments

@ankur22
Copy link
Collaborator

ankur22 commented Jun 13, 2023

Description

While working on #929, I noticed that in getDefaultBrowserContextOrByID we return the defaultContext when the requested context with the given id is not found. I changed this to panic when this occurred, but it panicked when running multiple k6 test runs (with multiple k6 instances) against a single chrome instance.

My guess as to why a browserContext cannot be found when we receive a onAttachedToTarget event is because each of the k6 instances mirrors the pages from all other k6 instances, but we're not mirroring the creation of the browserContexts. It would be great if we didn't also have to create the page that is associated with a different k6 instance and not the current one 🤔

Experiment

I ran a quick experiment where i returned nil from getDefaultBrowserContextOrMatchedID:

func (b *Browser) getDefaultBrowserContextOrMatchedID(id cdp.BrowserContextID) (*BrowserContext, error) {
	if b.context == nil {
		return nil, nil
	}

	if b.context.id != id {
		return nil, nil
	}

	return b.context, nil
}

and the caller would have to check for a nil browserCtx and return early, avoiding the need to create the requested page:

	if browserCtx == nil {
		return // Ignore requests to attach target for other k6 instances
	}

Which actually worked! So maybe there is a possibility of making this less complex and not needing to track pages from other k6 instances in the current k6 instance.

Originally posted by @ankur22 in #929 (comment)

Task

  1. Are there other side affects of not creating a page when we can't find the browserContext?
  2. Can we avoid/skip similar such cases with other objects or requests when objects aren't found in the current k6 instance as they only exist in another k6 instance?
  3. Can we remove the need for defaultContext?
  4. Any other ideas?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant