I’m working with N8N embedded in an iframe and need to extract URL parameters inside a custom node I built. The workflow receives data through URL parameters but I can’t access them using standard browser methods.
I’ve attempted several approaches:
- Using
window.location.href throws an error since window object isn’t available
- Tried Node.js approach with url module:
const urlParser = require('url');
let queryParams = new urlParser.URLSearchParams('id=abc123');
console.log(queryParams.get('id'));
The issue is I don’t know how to retrieve the actual URL string to feed into URLSearchParams. How can I access the current page URL and its parameters from within a custom N8N node environment?
The issue is that custom N8N nodes run in Node.js, not the browser - so there’s no window object available. You’re dealing with server-side execution here. URL parameters should come through the workflow trigger, not accessed directly in nodes. With webhook triggers, they’re in the request object. For manual triggers or testing, just define input parameters in your node config. Here’s a suggestion: capture URL parameters at the workflow entry point using a webhook node, then pass those values as workflow data to your custom node. The trigger extracts query parameters and feeds them to downstream nodes through N8N’s normal data flow. If you really need the parent frame URL, you’d have to set up message passing between the iframe and parent window, but that adds complexity and potential security issues.
you can’t mix client/server contexts like that. n8n nodes run server-side, so there’s no DOM access. use a webhook trigger with query params instead - they automatically become workflow data. then grab them in your custom node with this.getInputData() rather than parsing the url.
Been through this exact scenario embedding n8n workflows in client apps. The problem is architectural - your custom node runs in n8n’s backend, completely separate from the browser where your iframe lives. You can’t access window.location from the node execution environment.
Here’s what worked for me: add a preprocessing step before the workflow starts. I modified the iframe integration to grab URL parameters with regular JavaScript in the parent page, then pass those values as workflow variables through n8n’s API when triggering the workflow. Your custom node gets the parameters as normal input data instead of trying to parse URLs.
If you’re using webhook triggers, query parameters get parsed automatically and show up in the first node’s output. For manual triggers, add input fields to your workflow that your iframe’s JavaScript populates before execution starts.