K6 browser set allow-scripts permission

We ran some tests using k6 browser and we got the following error multiple times:

ERRO[0009] Blocked script execution in ‘about:blank’ because the document’s frame is sandboxed and the ‘allow-scripts’ permission is not set. browser_source=security line_number=6 source=browser stacktrace=“&{ [0xc000f4dec0 0xc000f4df00 0xc000f4df40 0xc001176100 0xc001176180 0xc0011761c0 0xc001176200 0xc001176240 0xc001176280 0xc0011762c0 0xc001176340 0xc001176380 0xc001176400 0xc001176440] }” url=“https://cdn.cookielaw.org/scripttemplates/202404.1.0/otBannerSdk.js

It is very annoying as it is difficult to follow other diagnostic logs. Is there a way to set allow-scripts permission in order to avoid it?

1 Like

Hi,

This might be related to what is explained in this document.

You can also try running the k6 browser like this:

K6_BROWSER_ARGS='allow-scripts' k6 run script.js

Hope this helps.

2 Likes

Hi @inancgumus

I appreciate your reply. I tried your solution and code works like a charm.

This K6 env var was very deeply hidden.

Thanks

1 Like

Hello Sir,

Thank you for your solution. However, it doesn’t work for me for some reason. I tried running the command shared by you and still getting below error:
‘Blocked script execution in ‘about:blank’ because the document’s frame is sandboxed and the ‘allow-scripts’ permission is not set.’
Is there any other insight/solution you can share please? Let me know if any information is required from my side.
Thank you in advance :slight_smile:

Hi @yogitalakhi18,

Have you added sandbox="allow-scripts" as explained in the linked article?

On Windows Powershell, setting an environment variable is like this:

$env:K6_BROWSER_ARGS="allow-scripts"; k6 run script.js

Hope this helps.

Hello, thank you for replying.
I went through the article shared by you but I couldn’t understand if sandbox=“allow-scripts” need to be set on the website itself or Is there any way to modify it via our k6 code as well?
PS: I tried with the command $env:K6_BROWSER_ARGS=“allow-scripts”; k6 run script.js but still getting the same error.

Yes, you need to add sandbox="allow-scripts" to the website itself.

@inancgumus Thanks for confirming. I will check with developers if that would be possible in my case. Thank you again :slight_smile:

1 Like