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()))();
    console.log(forge)
})

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());
   eval(pm.collectionVariables.get("forge_library"));
   console.log(this.forge)
})

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