Extracting query string parameters in N8N custom nodes when embedded in iframe

I’m working with N8N that’s embedded inside an iframe in my web application. I need to capture URL parameters from the parent page URL when my custom workflow node executes.

I’ve attempted several approaches but none seem to work properly:

  1. Tried using window.location.href but the window object isn’t available in the node context
  2. Attempted to use Node.js URL module like this:
const urlModule = require('url');
let queryParams = new urlModule.URLSearchParams('id=abc123');
console.log(queryParams.get('id'));

The issue with the second approach is that I can’t figure out how to actually retrieve the current URL to pass into URLSearchParams. The hardcoded string works for testing but I need the real URL.

Is there a way to access the browser URL or query parameters from within N8N custom nodes when running in an iframe context?

N8N nodes operate server-side, so they don’t have direct access to the browser’s environment where your iframe is embedded. A useful approach is to adapt your workflow to receive URL parameters as input. From your main application, you can extract the query parameters using JavaScript and then forward them to N8N, either via a webhook or by using an HTTP request node. If you set up a webhook, simply include the parameters in the body of your POST request. Alternatively, consider implementing a custom function node that accepts these parameters as input properties during the workflow execution. This method helps maintain a clear separation between your frontend and the N8N backend while allowing you to access the necessary data.

N8N custom nodes run server-side in Node.js, not in the browser where your iframe lives. You can’t access window.location or other browser APIs from inside the node. Instead, a practical solution is to pass the query parameters as input to your workflow. You can capture these parameters in your parent application using window.location.search in JavaScript, and then send them to N8N via a webhook trigger or an HTTP request node. If this data needs to be accessed frequently, consider setting up environment variables in N8N with your base URL information, keeping in mind that this won’t support dynamic query parameters.

yep, this confuses many with n8n. nodes run on the backend, so no access to browser elements like query params directly. i opt for postMessage to send params from the parent to the iframe, then i input those into the workflow. it works every time.