<h3 dir="auto">Issue Details</h3>
<ul dir="auto">
<li><strong>Electron Version:</strong>
<ul dir="auto">
<li>v6.0.0</li>
</ul>
</li>
<li><strong>Operating System:</strong>
<ul dir="auto">
<li>MacOS 10.14</li>
</ul>
</li>
<li><strong>Last Known Working Electron version:</strong>
<ul dir="auto">
<li>N/A</li>
</ul>
</li>
</ul>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Functional <a href="https://electronjs.org/docs/tutorial/security#12-disable-or-limit-navigation" rel="nofollow">example code</a> that prevents navigation.</p>
<h3 dir="auto">Actual Behavior</h3>
<p dir="auto">Call back is not called, behavoir is not prevented, depending on project blank HTML document is sometimes loaded.</p>
<h3 dir="auto">To Reproduce</h3>
<ol dir="auto">
<li>Clone the <a href="https://github.com/electron/electron-quick-start">Electron Quick Start</a> project</li>
<li>Update <code class="notranslate">main.js</code> with the code below</li>
<li>Execute <code class="notranslate">window.location = 'https://example.com'</code></li>
<li>Note navigation occurs and no <code class="notranslate">console.log</code> output</li>
</ol>
<h5 dir="auto">main.js</h5>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// Modules to control application life and create native browser window
const {
  app,
  BrowserWindow
} = require('electron')
const path = require('path')

// 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,
    webPreferences: {
      sandbox: true,
      webSecurity: true,
      contextIsolation: true,
      webviewTag: false,
      enableRemoteModule: false,
      allowRunningInsecureContent: false,
      nodeIntegration: false,
      nodeIntegrationInWorker: false,
      nodeIntegrationInSubFrames: false,
      nativeWindowOpen: false,
      safeDialogs: true,
      preload: path.join(__dirname, 'preload.js')
    }
  })

  // and load the index.html of the app.
  mainWindow.loadFile('index.html')

  // 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 macOS 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 macOS 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.
app.on('web-contents-created', (_, contents) =&gt; {
  contents.on('will-navigate', (event, navigationUrl) =&gt; {
    console.log(`[will-navigate] ${navigationUrl}`)
    event.preventDefault()
  })
})"><pre class="notranslate"><span class="pl-c">// Modules to control application life and create native browser window</span>
<span class="pl-k">const</span> <span class="pl-kos">{</span>
  app<span class="pl-kos">,</span>
  BrowserWindow
<span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'electron'</span><span class="pl-kos">)</span>
<span class="pl-k">const</span> <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'path'</span><span class="pl-kos">)</span>

<span class="pl-c">// Keep a global reference of the window object, if you don't, the window will</span>
<span class="pl-c">// be closed automatically when the JavaScript object is garbage collected.</span>
<span class="pl-k">let</span> <span class="pl-s1">mainWindow</span>

<span class="pl-k">function</span> <span class="pl-en">createWindow</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// Create the browser window.</span>
  <span class="pl-s1">mainWindow</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">BrowserWindow</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
    <span class="pl-c1">width</span>: <span class="pl-c1">800</span><span class="pl-kos">,</span>
    <span class="pl-c1">height</span>: <span class="pl-c1">600</span><span class="pl-kos">,</span>
    <span class="pl-c1">webPreferences</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">sandbox</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
      <span class="pl-c1">webSecurity</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
      <span class="pl-c1">contextIsolation</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
      <span class="pl-c1">webviewTag</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
      <span class="pl-c1">enableRemoteModule</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
      <span class="pl-c1">allowRunningInsecureContent</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
      <span class="pl-c1">nodeIntegration</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
      <span class="pl-c1">nodeIntegrationInWorker</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
      <span class="pl-c1">nodeIntegrationInSubFrames</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
      <span class="pl-c1">nativeWindowOpen</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
      <span class="pl-c1">safeDialogs</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
      <span class="pl-c1">preload</span>: <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">join</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span><span class="pl-kos">,</span> <span class="pl-s">'preload.js'</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>

  <span class="pl-c">// and load the index.html of the app.</span>
  <span class="pl-s1">mainWindow</span><span class="pl-kos">.</span><span class="pl-en">loadFile</span><span class="pl-kos">(</span><span class="pl-s">'index.html'</span><span class="pl-kos">)</span>

  <span class="pl-c">// Open the DevTools.</span>
  <span class="pl-s1">mainWindow</span><span class="pl-kos">.</span><span class="pl-c1">webContents</span><span class="pl-kos">.</span><span class="pl-en">openDevTools</span><span class="pl-kos">(</span><span class="pl-kos">)</span>

  <span class="pl-c">// Emitted when the window is closed.</span>
  <span class="pl-s1">mainWindow</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">'closed'</span><span class="pl-kos">,</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-c">// Dereference the window object, usually you would store windows</span>
    <span class="pl-c">// in an array if your app supports multi windows, this is the time</span>
    <span class="pl-c">// when you should delete the corresponding element.</span>
    <span class="pl-s1">mainWindow</span> <span class="pl-c1">=</span> <span class="pl-c1">null</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-c">// This method will be called when Electron has finished</span>
<span class="pl-c">// initialization and is ready to create browser windows.</span>
<span class="pl-c">// Some APIs can only be used after this event occurs.</span>
<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">'ready'</span><span class="pl-kos">,</span> <span class="pl-s1">createWindow</span><span class="pl-kos">)</span>

<span class="pl-c">// Quit when all windows are closed.</span>
<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">'window-all-closed'</span><span class="pl-kos">,</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// On macOS it is common for applications and their menu bar</span>
  <span class="pl-c">// to stay active until the user quits explicitly with Cmd + Q</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">platform</span> <span class="pl-c1">!==</span> <span class="pl-s">'darwin'</span><span class="pl-kos">)</span> <span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">quit</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>

<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">'activate'</span><span class="pl-kos">,</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// On macOS it's common to re-create a window in the app when the</span>
  <span class="pl-c">// dock icon is clicked and there are no other windows open.</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">mainWindow</span> <span class="pl-c1">===</span> <span class="pl-c1">null</span><span class="pl-kos">)</span> <span class="pl-en">createWindow</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>

<span class="pl-c">// In this file you can include the rest of your app's specific main process</span>
<span class="pl-c">// code. You can also put them in separate files and require them here.</span>
<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">'web-contents-created'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">_</span><span class="pl-kos">,</span> <span class="pl-s1">contents</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-s1">contents</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">'will-navigate'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">event</span><span class="pl-kos">,</span> <span class="pl-s1">navigationUrl</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`[will-navigate] <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">navigationUrl</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span>
    <span class="pl-s1">event</span><span class="pl-kos">.</span><span class="pl-en">preventDefault</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<h3 dir="auto">Preflight Checklist</h3>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the <a href="https://github.com/electron/electron/blob/master/CONTRIBUTING.md">Contributing Guidelines</a> for this project.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow the <a href="https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md">Code of Conduct</a> that this project adheres to.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the issue tracker for an issue that matches the one I want to file, without success. <em><strong>This might be a duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="427233346" data-permission-text="Title is private" data-url="https://github.com/electron/electron/issues/17617" data-hovercard-type="issue" data-hovercard-url="/electron/electron/issues/17617/hovercard" href="https://github.com/electron/electron/issues/17617">#17617</a> but I have no idea how to check.</strong></em></li>
</ul>
<h3 dir="auto">Issue Details</h3>
<ul dir="auto">
<li><strong>Electron Version:</strong>
<ul dir="auto">
<li>
 3.1.6 (Visual Studio Code 1.33.1)
</li>
</ul>
</li>
<li><strong>Operating System:</strong>
<ul dir="auto">
<li>
 macOS 10.14.4
</li>
</ul>
</li>
<li><strong>Last Known Working Electron version:</strong>:
<ul dir="auto">
<li>
 N/A
</li>
</ul>
</li>
</ul>
<h3 dir="auto">Expected Behavior</h3>

<p dir="auto">No crash.</p>
<h3 dir="auto">Actual Behavior</h3>

<p dir="auto">The app crashes.</p>
<h3 dir="auto">To Reproduce</h3>

<p dir="auto">Not quite sure how to reproduce, but the crash is from <a href="https://code.visualstudio.com/" rel="nofollow">Visual Studio Code</a>.</p>


<h3 dir="auto">Screenshots</h3>

<p dir="auto">N/A</p>
<h3 dir="auto">Additional Information</h3>

<p dir="auto">Crash report: <a href="https://gist.github.com/Coder-256/d6f7c628335e3fe96547e55aa7f6802a">Electron.crash</a></p>
<p dir="auto">I've narrowed it down to somewhere in this function:<br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/electron/electron/blob/73158a6419a3e2da9e4d523e1131052abd28fbbb/atom/browser/window_list.cc#L82-L90">electron/atom/browser/window_list.cc</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 82 to 90
      in
      <a data-pjax="true" class="commit-tease-sha" href="/electron/electron/commit/73158a6419a3e2da9e4d523e1131052abd28fbbb">73158a6</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L82" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="82"></td>
          <td id="LC82" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">void</span> <span class="pl-en">WindowList::CloseAllWindows</span>() { </td>
        </tr>

        <tr class="border-0">
          <td id="L83" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="83"></td>
          <td id="LC83" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   WindowVector windows = <span class="pl-c1">GetInstance</span>()-&gt;<span class="pl-smi">windows_</span>; </td>
        </tr>

        <tr class="border-0">
          <td id="L84" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="84"></td>
          <td id="LC84" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> #<span class="pl-k">if</span> defined(OS_MACOSX) </td>
        </tr>

        <tr class="border-0">
          <td id="L85" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="85"></td>
          <td id="LC85" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-c1">std::reverse</span>(windows.<span class="pl-c1">begin</span>(), windows.<span class="pl-c1">end</span>()); </td>
        </tr>

        <tr class="border-0">
          <td id="L86" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="86"></td>
          <td id="LC86" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> #<span class="pl-k">endif</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L87" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="87"></td>
          <td id="LC87" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">for</span> (<span class="pl-k">auto</span>* <span class="pl-k">const</span>&amp; window : windows) </td>
        </tr>

        <tr class="border-0">
          <td id="L88" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="88"></td>
          <td id="LC88" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">if</span> (!window-&gt;<span class="pl-c1">IsClosed</span>()) </td>
        </tr>

        <tr class="border-0">
          <td id="L89" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="89"></td>
          <td id="LC89" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       window-&gt;<span class="pl-c1">Close</span>(); </td>
        </tr>

        <tr class="border-0">
          <td id="L90" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="90"></td>
          <td id="LC90" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> } </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">Sorry if I haven't provided enough information, if I'm missing anything please let me know.</p>