Skip to content

Pre-request script copied from Postman causes request to time out #9031

Description

@MrMingFang

Expected Behavior

A pre-request script copied from a working Postman request should execute successfully within Insomnia's time limit. After the script completes, the main HTTP request should be sent as configured.

Image

Actual Behavior

When I copy a pre-request script directly from Postman and paste it into Insomnia's "Pre-Request" script editor, the request execution hangs and eventually results in a timeout error. The main HTTP request is never sent. The exact same script works perfectly and executes quickly in Postman.

Image

Reproduction Steps

Create a request in Postman with a functional pre-request script blow.
Copy the entire content of the Postman pre-request script.
In Insomnia, create a new HTTP request.
Navigate to the Script tab and select the pre Request section.
Paste the script copied from Postman into the editor.
Click "Send" to execute the request.
Observe that the request loading indicator runs indefinitely until a timeout error is displayed.

postman pre-script:

console.log('Pre-request Script from Request start');

if (pm.request.method !== 'GET' && !(pm.request.headers.has('x-csrf-token'))) {

  var csrfRequest = pm.request.clone();
  csrfRequest.method = 'GET';
  if (pm.request.method === 'POST') {
    csrfRequest.url = pm.request.url + '?$top=1';
  }

  csrfRequest.upsertHeader({
    key: 'x-csrf-token',
    value: 'fetch'
  });

  pm.sendRequest(csrfRequest, function(err, res) {
    console.log('pm.sendRequest start');
    if (err) {
      console.log(err);
    } else {
      var csrfToken = res.headers.get('x-csrf-token');
      if (csrfToken) {
        console.log('csrfToken fetched:' + csrfToken);
        pm.request.headers.upsert({
          key: 'x-csrf-token',
          value: csrfToken
        });
      } else {
        console.log('No csrf token fetched');
      }
    }
    console.log('pm.sendRequest end');
  });
}

console.log('Pre-request Script from Request end');

COPY TO postman

console.log('Pre-request Script from Request start');

if (insomnia.request.method !== 'GET' && !(insomnia.request.headers.has('x-csrf-token'))) {

  var csrfRequest = insomnia.request.clone();
  csrfRequest.method = 'GET';
  if (insomnia.request.method === 'POST') {
    csrfRequest.url = insomnia.request.url + '?$top=1';
  }

  csrfRequest.upsertHeader({
    key: 'x-csrf-token',
    value: 'fetch'
  });

  insomnia.sendRequest(csrfRequest, function(err, res) {
    console.log('insomnia.sendRequest start');
    if (err) {
      console.log(err);
    } else {
      var csrfToken = res.headers.get('x-csrf-token');
      if (csrfToken) {
        console.log('csrfToken fetched:' + csrfToken);
        insomnia.request.headers.upsert({
          key: 'x-csrf-token',
          value: csrfToken
        });
      } else {
        console.log('No csrf token fetched');
      }
    }
    console.log('insomnia.sendRequest end');
  });
}

console.log('Pre-request Script from Request end');

Is there an existing issue for this?

Which sync method do you use?

  • Git sync.
  • Insomnia Cloud sync.
  • Local only

Additional Information

No response

Insomnia Version

11.4.0

What operating system are you using?

Windows

Operating System Version

WIN11 23H2 22631.5768

Installation method

GITHUB Insomnia.Core-11.4.0.exe

Last Known Working Insomnia version

No response

Activity

  1. added
    S-verifiedStatus: Verified by maintainer
    and removed
    S-unverifiedStatus: Unverified by maintainer
    on Aug 22, 2025
  2. ihexxa commented on Aug 22, 2025

    @ihexxa
    Contributor

    Hi @MrMingFang ,

    It looks like related to the request body mode and #8897, you can add one row to enable it manually temporarily:

      if (insomnia.request.method === 'POST') {
        csrfRequest.url = insomnia.request.url + '?$top=1';
        csrfRequest.body.mode = "raw"; // <-- add this
      }
    

    Will check it.

  3. MrMingFang commented on Aug 23, 2025

    @MrMingFang
    Author

    Thanks, that works! 🎉
    I added csrfRequest.body.mode = "raw"; as suggested, and it fixed the issue.

  4. self-assigned this
    on Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

B-bugBug: general classificationS-verifiedStatus: Verified by maintainer

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions