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

browserContext.addInitScript differs in behaviour depending on type of script #4337

Open
1 task
ankur22 opened this issue Mar 19, 2024 · 0 comments
Open
1 task

Comments

@ankur22
Copy link
Contributor

ankur22 commented Mar 19, 2024

Brief summary

browserContext.addInitScript differs in behaviour depending on type of script, e.g. if you pass in a string vs a non string.

xk6-browser version

v1.4.3

OS

NA

Chrome version

NA

Docker version and image (if applicable)

NA

Steps to reproduce the problem

This works as intended so Math.random is overridden and will always return 0:

  const browserContext = browser.newContext();
  browserContext.addInitScript("Math.random = function(){return 0}");

This will not work as intended so Math.random isn't overridden and returns a random number:

  const browserContext = browser.newContext();
  browserContext.addInitScript(Math.random = function(){return 0});

Expected behaviour

The behaviour should be the same, and match what currently happens when a string function is passed in.

Actual behaviour

The behaviour differs.

Tasks

Preview Give feedback
@ankur22 ankur22 added the bug label Mar 19, 2024
@inancgumus inancgumus transferred this issue from grafana/xk6-browser Jan 30, 2025
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

2 participants