Deep Linking and Protocol Handlers
Let users launch and navigate your Electron app from custom URL schemes, a key lifecycle integration that complements startup events and updates.
Deep Linking and Protocol Handlers is a free Electron Desktop App Development lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Electron Desktop App Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Launching From a Link
Deep linking lets a URL like myapp://open/project/42 launch or focus your app and jump straight to content.
Custom Protocols
Register a custom URL scheme so the OS knows links of that type belong to your app.
app.setAsDefaultProtocolClient('myapp');Parsing the Deep Link
Extract the path and parameters from the incoming URL to decide where to navigate.
function parseDeepLink(url) {
const u = new URL(url);
return { host: u.host, path: u.pathname };
}
console.log(parseDeepLink('myapp://open/project/42'));Handling Links on macOS
On macOS, deep links arrive via the open-url event, even while the app is running.
app.on('open-url', (event, url) => {
event.preventDefault();
handleLink(url);
});Handling Links on Windows and Linux
On Windows and Linux the URL comes in as a command-line argument, so inspect process.argv on launch.
function urlFromArgv(argv) {
return argv.find(a => a.startsWith('myapp://'));
}
console.log(urlFromArgv(['electron', '.', 'myapp://open/5']));Single Instance Coordination
Use the single instance lock so a second launch forwards its URL to the already-running app instead of starting a new one.
const gotLock = app.requestSingleInstanceLock();
if (!gotLock) app.quit();second-instance Event
The second-instance event delivers the new command line, where the deep link lives, and lets you focus the main window.
app.on('second-instance', (e, argv) => {
const url = urlFromArgv(argv);
if (url) handleLink(url);
});Cold Start vs Warm Start
Handle both cases: the app launched fresh by the link (cold) and the app already open (warm). Route both to the same handler.
Validating the Link
Never trust a deep link blindly. Validate the path and parameters before acting on them to avoid abuse.
Testing Deep Links
Test by typing the URL into a browser or terminal. During development the scheme must point at your packaged or running app.
Use Cases
Deep links power OAuth callbacks, sharing, and notifications that jump straight to relevant content, tying nicely into the app lifecycle.
Quick Check
Test your deep linking knowledge.
Recap
You learned to register a custom protocol, parse deep links, handle them across platforms, coordinate with the single-instance lock, and validate input, enabling URL-driven app navigation.
Frequently asked questions
Is the “Deep Linking and Protocol Handlers” lesson free?
Yes — the full text of “Deep Linking and Protocol Handlers” is free to read here on the web, and the Electron Desktop App Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Electron Desktop App Development course, upgrade to CoddyKit PRO.
What will I learn in “Deep Linking and Protocol Handlers”?
Let users launch and navigate your Electron app from custom URL schemes, a key lifecycle integration that complements startup events and updates. You practise Electron Desktop App Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Electron Desktop App Development?
No prior experience is required. Electron Desktop App Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Deep Linking and Protocol Handlers” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Electron Desktop App Development lesson?
Yes. Every Electron Desktop App Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Managing App Lifecycle Events
- Auto-Updates Implementation
- Crash Reporting
- Deep Linking and Protocol Handlers