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

Export Chromium BrowserType implementation directly #485

Closed
imiric opened this issue Aug 9, 2022 · 0 comments · Fixed by #515
Closed

Export Chromium BrowserType implementation directly #485

imiric opened this issue Aug 9, 2022 · 0 comments · Fixed by #515
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@imiric
Copy link
Contributor

imiric commented Aug 9, 2022

In #462 we made a chromium object importable in scripts, but the way it's done is a bit convoluted:

xk6-browser/main.go

Lines 61 to 68 in aadaffe

func (mi *ModuleInstance) Exports() k6modules.Exports {
return k6modules.Exports{
Named: map[string]interface{}{
"chromium": mi.mod,
"devices": mi.mod.Devices,
},
}
}

That is, "chromium" actually points to the JSModule itself, and calling chromium.launch() calls the module-level Launch() wrapper, which internally creates a Chromium BrowserType and calls BrowserType.Launch().

Which means this is possible:

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

export default function() {
  // logs v0.4.0, the xk6-browser version, not the Chromium version
  console.log(chromium.version);
  // logs the device configuration map, which should be browser-agnostic
  console.log(chromium.devices);
}

Suggested solution

As mentioned here and here, import { chromium } from 'k6/x/browser'; should actually import the Chromium BrowserType instance directly, so the script can call all of its public methods. This would allow us to easily support other BrowserType implementations in the future.

And if the user wants access to module-level attributes, the script should import the module instead, e.g. import k6b from 'k6/x/browser;.

@imiric imiric added the enhancement New feature or request label Aug 9, 2022
@imiric imiric added this to the v0.5.0 milestone Aug 9, 2022
@imiric imiric self-assigned this Aug 31, 2022
imiric pushed a commit that referenced this issue Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant