Load Node-forge library in Postman pre request scrip

I’m trying to load node-forge which has an implementation of PKSC#1 into postman as a pre-request script

pm.sendRequest("https://unpkg.com/node-forge@1.0.0/dist/forge.min.js", function(err, res) {
    (new Function(res.text()))();

but getting below error

ReferenceError: window is not defined

Hi @Sreekar23071999

Have a look at this…

Hello @w4dd325

Getting the same error “ReferenceError: window is not defined” even after adding it as mentioned in the above article.

pm.sendRequest("https://unpkg.com/node-forge@1.0.0/dist/forge.min.js", function(err, res) {
   pm.collectionVariables.set("forge_library", res.text());

Postman Version 9.28.2
UI Version: 9.28.2-ui-220812-1517
Desktop Platform Version: 9.27.0 (9.27.0)

OS: macOS Monterey

It looks like the lib interacts with a browser window… But Postman is built more like a basic nodeJS, it doesn’t have a browser window to interact with.

Postman has a powerful runtime based on Node .js that allows you to add dynamic behavior to requests and collections.

I think this is the issue, Postman doesn’t know how to interpret the browser parts of the lib.

Thanks for the reply @w4dd325

I’m trying to do PKCS#1_1.5 encryption on my request payload before firing the API but the inbuilt CryptoJS doesn’t support any RSA Schemes, so I was trying to import a lib that has this implementation so far all my attempts have been futile, happen to know any JS libs that implement PKCS#1_1.5 and work in postman?
Native crypto module of node.js does support this, is there a way to access the same on postman?

Managed to get this to work by creating an empty window object

window = {};
eval(pm.globals.get(‘forge’) );

and then i’ve got error : ReferenceError: URLSearchParams is not defined

Hi All, Finally it’s working on me.
Follow this tutorial : Node Forge For Postman