title: Open app and pass parameters with deep linking using Electron (macOS)
body: <p>I want to open app and pass parameters with deep linking using Electron (macOS). </p>
  
  <p><a href="https://github.com/oikonomopo/electron-deep-linking-mac-win" rel="noreferrer">Project 'electron-deep-linking-mac-win' is on GitHub</a>.</p>
  
  <h2><a href="https://raw.githubusercontent.com/oikonomopo/electron-deep-linking-osx/master/electron-deeplinking-osx-example.gif" rel="noreferrer"><img src="https://raw.githubusercontent.com/oikonomopo/electron-deep-linking-osx/master/electron-deeplinking-osx-example.gif" alt="enter image description here"></a></h2>
  
  <p>Edited <code>package.json</code>, following <a href="https://github.com/electron-userland/electron-builder#quick-setup-guide" rel="noreferrer">‘electron-builder’ quick-setup-guide</a> to produce mac installer:</p>
  
  <pre><code>{
    "name": "electron-deep-linking-osx",
    "version": "1.0.0",
    "description": "A minimal Electron application with Deep Linking (OSX)",
    "main": "main.js",
    "scripts": {
      "start": "electron .",
      "pack": "build --dir",
      "dist": "build"
    },
    "repository": "https://github.com/oikonomopo/electron-deep-linking-osx",
    "keywords": [
      "Electron",
      "osx",
      "deep-linking"
    ],
    "author": "GitHub",
    "license": "CC0-1.0",
    "devDependencies": {
      "electron": "1.6.6",
      "electron-builder": "17.1.2"
    },
    "build": {
      "appId": "your.id",
      "mac": {
        "category": "your.app.category.type"
      },
      "protocols": {
        "name": "myApp",
        "schemes": ["myApp"]
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <p>Edited <code>main.js</code>, appended code to <a href="https://electron.atom.io/docs/api/app/#appsetasdefaultprotocolclientprotocol-path-args-macos-windows" rel="noreferrer">register <code>myapp</code> url scheme protocol</a>, listen <a href="https://electron.atom.io/docs/api/app/#event-open-url-macos" rel="noreferrer">'open-url' events</a> and log the arguments:</p>
  
  <pre><code>const electron = require('electron')
  // Module to control application life.
  const app = electron.app
  // Module to create native browser window.
  const BrowserWindow = electron.BrowserWindow
  // Module with utilities for working with file and directory paths.
  const path = require('path')
  // Module with utilities for URL resolution and parsing.
  const url = require('url')
  // Module to display native system dialogs for opening and saving files, alerting, etc.
  const dialog = electron.dialog
  
  // Keep a global reference of the window object, if you don't, the window will
  // be closed automatically when the JavaScript object is garbage collected.
  let mainWindow
  
  function createWindow () {
    // Create the browser window.
    mainWindow = new BrowserWindow({width: 800, height: 600})
  
    // and load the index.html of the app.
    mainWindow.loadURL(url.format({
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file:',
      slashes: true
    }))
  
    // Open the DevTools.
    mainWindow.webContents.openDevTools()
  
    // Emitted when the window is closed.
    mainWindow.on('closed', function () {
      // Dereference the window object, usually you would store windows
      // in an array if your app supports multi windows, this is the time
      // when you should delete the corresponding element.
      mainWindow = null
    })
  }
  
  // This method will be called when Electron has finished
  // initialization and is ready to create browser windows.
  // Some APIs can only be used after this event occurs.
  app.on('ready', createWindow)
  
  // Quit when all windows are closed.
  app.on('window-all-closed', function () {
    // On OS X it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform !== 'darwin') {
      app.quit()
    }
  })
  
  app.on('activate', function () {
    // On OS X it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (mainWindow === null) {
      createWindow()
    }
  })
  
  // In this file you can include the rest of your app's specific main process
  // code. You can also put them in separate files and require them here.
  
  // The setAsDefaultProtocolClient only works on packaged versions of the application
  app.setAsDefaultProtocolClient('myApp')
  
  // Protocol handler for osx
  app.on('open-url', function (event, url) {
    event.preventDefault();
    log("open-url event: " + url)
  
    dialog.showErrorBox('open-url', `You arrived from: ${url}`)
  })
  
  // Log both at terminal and at browser
  function log(s) {
      console.log(s)
      if (mainWindow &amp;&amp; mainWindow.webContents) {
          mainWindow.webContents.executeJavaScript(`console.log("${s}")`)
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Steps to come to life:-)</p>
  
  <pre><code># Clone this repository
  git clone https://github.com/oikonomopo/electron-deep-linking-mac-win.git
  # Go into the repository
  cd electron-deep-linking-mac-win
  # Install dependencies
  npm install
  # Run the app
  npm start
  # Produce installer
  npm run dist
  </code></pre>
  
  <p>After running the installer (<code>electron-deep-linking-mac-win/dist/electron-quick-start-1.0.0.dmg</code>), i try to open electron-deep-linking-os app with deep linking, entering <code>myapp://param</code> at Safari address bar.</p>
  
  <ol>
  <li><p>If app is opened, it activates and i can see the dialog and the log <code>open-url event: myapp://param</code>!</p></li>
  <li><p><strong>If app is closed, it opens, dialog is shown with proper url but isn't logged to dev console!</strong></p></li>
  </ol>
  
  <p><strong>Why with <code>dialog</code> module <code>url</code> is showing properly, but isn't logged to dev console?
   How to log it?</strong></p>
  
  <p><em>Looking for solution using only <a href="https://github.com/electron-userland/electron-builder/" rel="noreferrer"><code>electron-builder</code></a> (<a href="https://stackoverflow.com/questions/37113815/electron-builder-vs-electron-packager">which uses <code>electron-packager</code></a>)!</em></p>