I’m working with N8N that’s embedded in my app through an iframe. I need to extract URL parameters from the browser address bar when my custom workflow node runs.
I’ve attempted different approaches but keep running into issues:
window.location.href throws an error because window object isn’t available
Tried using Node.js url module like this:
const urlModule = require('url');
let queryParams = new urlModule.URLSearchParams('user=abc123');
console.log(queryParams.get('user'));
The problem with approach #2 is that I can’t figure out how to actually get the current page URL to pass into URLSearchParams. The hardcoded string works but that’s not useful for my real scenario.
How can I access the actual browser URL with its parameters from inside a custom N8N node?
Unfortunately, you can’t do this directly because of how N8N works. Custom nodes run in the backend Node.js environment, which is completely separate from your browser iframe. That’s why window.location and other browser APIs won’t work.
The cleanest fix I’ve found is passing URL parameters as workflow variables when you initialize everything. When your app loads the N8N iframe, grab the parameters from the parent window and inject them into the workflow using N8N’s variable system or webhook parameters.
If you control the parent app, you can also set up postMessage communication between your app and the iframe to send URL data when needed. I’ve used this approach successfully for similar embedded setups where the workflow needs data from the hosting page.
I faced a similar issue while using N8N. Custom nodes operate in a backend environment and thus lack access to browser-level variables such as URL parameters. Instead, I’d recommend extracting the URL parameters directly from the parent application before passing them to your workflow. This can be done using N8N’s input data variables or by sending them through an HTTP trigger. It might require rethinking your workflow initiation, but it’s a much more consistent approach than trying to access them directly from the iframe.
yep, totally a classic n8n issue! your custom node runs on the server side, making browser stuff like URL params inaccessible. what i do is grab the query string in the parent window usin window.location.search and send it to n8n via the initial webhook or workflow variables. it’s a pain, but it works!