insomnia icon indicating copy to clipboard operation
insomnia copied to clipboard

Cannot render URL in prerequest script

Open AvaPL opened this issue 2 months ago • 0 comments

Expected Behavior

I want to migrate a prerequest script from Postman. In one of its steps, it obtains a rendered URL with variables substituted.

const url = pm.request.url
console.log(`url = ${url}`)
const renderedUrl = pm.variables.replaceIn(pm.request.url)
console.log(`renderedUrl = ${renderedUrl}`)

Example output:

url = https://{{host}}/{{path}}?queryParam={{queryParam}}
renderedUrl = https://postman-echo.com/get?queryParam=foo

I try to achieve the same with Insomnia via:

const url = insomnia.request.url
console.log(`url = ${url}`)
const renderedUrl = insomnia.variables.replaceIn(insomnia.request.url)
console.log(`renderedUrl = ${renderedUrl}`)

Actual Behavior

I get:

* Error from Pre-request or after-response script:
* template2.split is not a function;
* Stack: TypeError: template2.split is not a function
*     at Interpolator.renderWithFaker (file:///Applications/Insomnia.app/Contents/Resources/app.asar/entry.hidden-window.min.js:82248:32)
*     at Interpolator.render (file:///Applications/Insomnia.app/Contents/Resources/app.asar/entry.hidden-window.min.js:82245:42)
*     at Variables.replaceIn (file:///Applications/Insomnia.app/Contents/Resources/app.asar/entry.hidden-window.min.js:85625:30)
*     at fn0 (eval at runScript (file:///Applications/Insomnia.app/Contents/Resources/app.asar/entry.hidden-window.min.js:86477:25), <anonymous>:9:40)
*     at eval (eval at runScript (file:///Applications/Insomnia.app/Contents/Resources/app.asar/entry.hidden-window.min.js:86477:25), <anonymous>:13:13)
*     at runScript (file:///Applications/Insomnia.app/Contents/Resources/app.asar/entry.hidden-window.min.js:86497:39)
*     at async file:///Applications/Insomnia.app/Contents/Resources/app.asar/entry.hidden-window.min.js:86453:23;

I assume it's because replaceIn requires a string. What is more, the URL that is obtained from insomnia.request.url doesn't contain query params:

url = https://{{_.host}}/{{_.path}}

Reproduction Steps

No response

Is there an existing issue for this?

Which sync method do you use?

  • [ ] Git sync.
  • [ ] Insomnia Cloud sync.
  • [x] Local only

Additional Information

No response

Insomnia Version

12.0.0

What operating system are you using?

macOS

Operating System Version

15.6.1

Installation method

Download from insomnia.rest

Last Known Working Insomnia version

No response

AvaPL avatar Nov 06 '25 20:11 AvaPL