JS/TS SDK: how to use crypto in js SDK

Gatling version: 3.11.5 (must be up to date)
Gatling flavor: java kotlin scala javascript typescript
Gatling build tool: maven gradle sbt bundle npm

I read the guidelines and how to ask a question topics.
I provided a SSCCE (or at least, all information to help the community understand my topic)
I copied output I observe, and explain what I think should be.

Hi, dear Gatling team,

I’m trying to create uuidv4 in gatling js for unique request id. I’m existing crypto function in node, but got error: “The package “node:crypto” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node’” to do that, which will remove this error.”. From this post: JS/TS SDK: node fs compatibility - Gatling (Open-Source) - Gatling, I understand that gatling js is using graal-js so that the node crypto cannot be used. Can I ask what’s the alternative solution to generate uuidv4 in gatling js, is there something like crypto in graal-js, thanks

Best,
Terence

Not sure what you mean.
uuid - npm seems to be 0 deps, so no dep to the node SDK.

Thanks for suggesting uuid package, I was using node built-in crypto package. However, now I tried to use uuid, I use v4 in my code:

import { v4 as uuidv4 } from “uuid”;

I got the following error:

08:53:18.841 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-2’ failed to execute: o.g.p.PolyglotException: Error: crypto.getRandomValues() not supported. See GitHub - uuidjs/uuid: Generate RFC-compliant UUIDs in JavaScript

As a workaround, have you tried using Gatling built-in Expression Language functions? Gatling session scripting reference - Expression Language

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.