<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.</li>
</ul>
<h3 dir="auto">Issue Details</h3>
<ul dir="auto">
<li>
<p dir="auto"><strong>Electron Version:</strong></p>
<ul dir="auto">
<li>LATEST</li>
</ul>
</li>
<li>
<p dir="auto"><strong>Operating System:</strong></p>
<ul dir="auto">
<li>macOS 10.13.6</li>
</ul>
</li>
</ul>
<h3 dir="auto">Expected Behavior</h3>

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
const filter = {
     urls: [
          &quot;file://*.sobot.com/*&quot;
     ]
}

browserWindow.webContents.session.webRequest.onBeforeRequest(filter,  (details, callback) =&gt; {
            const { id, url, method, resourceType, timestamp, uploadData } = details;
            // url === &quot;file://users/liutong/Desktop/**/projectName/app/***&quot;
           callback({
                cancel: false,
                redirectURL: 'http' + url.slice(4)
            })
        })"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">filter</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
     <span class="pl-c1">urls</span>: <span class="pl-kos">[</span>
          <span class="pl-s">"file://*.sobot.com/*"</span>
     <span class="pl-kos">]</span>
<span class="pl-kos">}</span>

<span class="pl-s1">browserWindow</span><span class="pl-kos">.</span><span class="pl-c1">webContents</span><span class="pl-kos">.</span><span class="pl-c1">session</span><span class="pl-kos">.</span><span class="pl-c1">webRequest</span><span class="pl-kos">.</span><span class="pl-en">onBeforeRequest</span><span class="pl-kos">(</span><span class="pl-s1">filter</span><span class="pl-kos">,</span>  <span class="pl-kos">(</span><span class="pl-s1">details</span><span class="pl-kos">,</span> <span class="pl-s1">callback</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
            <span class="pl-k">const</span> <span class="pl-kos">{</span> id<span class="pl-kos">,</span> url<span class="pl-kos">,</span> method<span class="pl-kos">,</span> resourceType<span class="pl-kos">,</span> timestamp<span class="pl-kos">,</span> uploadData <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">details</span><span class="pl-kos">;</span>
            <span class="pl-c">// url === "file://users/liutong/Desktop/**/projectName/app/***"</span>
           <span class="pl-s1">callback</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
                <span class="pl-c1">cancel</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
                <span class="pl-c1">redirectURL</span>: <span class="pl-s">'http'</span> <span class="pl-c1">+</span> <span class="pl-s1">url</span><span class="pl-kos">.</span><span class="pl-en">slice</span><span class="pl-kos">(</span><span class="pl-c1">4</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>
<p dir="auto">The callback of <code class="notranslate">onBeforeRequest</code> will be called by any request from the file scheme.</p>
<h3 dir="auto">Actual Behavior</h3>

<p dir="auto">For the above codes, I just want to redirect a request that contains the '*.sobot.com' domain,<br>
But I received a URL from the local path of <code class="notranslate">/users/Oliver/Desktop</code> in the callback of <code class="notranslate">onBeforeRequest</code>.</p>
<p dir="auto">When I add "file://*.sobot.com/*" a rule in the array, for the rule, I actually expected it only to match request that domain is '.sobot.com', but It appears to listen to all requests. e.g</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ &quot;file://users/Oliver/Desktop/**/projectName/app/caching_resources/***&quot; ]"><pre class="notranslate"><code class="notranslate">[ "file://users/Oliver/Desktop/**/projectName/app/caching_resources/***" ]
</code></pre></div>
<h3 dir="auto">To Reproduce</h3>



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

<h3 dir="auto">Additional Information</h3>

<p dir="auto">As for my final purpose, you can refer to this <a href="https://github.com/electron/electron/issues/19200" data-hovercard-type="issue" data-hovercard-url="/electron/electron/issues/19200/hovercard">issue</a>. so my fallback is to exclude any request that contains a path of 'caching_resources' as to redirect to the <code class="notranslate">HTTP</code> scheme.</p>
<ul dir="auto">
<li>Electron version: 1.7.9</li>
<li>Operating system: macOS</li>
</ul>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">The callback should be used only for URLs matching the filter.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const filter = { urls: ['*://www.googleapis.com'] };
session.defaultSession.webRequest.onBeforeRequest(filter, (details, callback) =&gt; {
  console.log('onBeforeRequest: ', details);
  callback({ cancel: true });
});"><pre class="notranslate"><code class="notranslate">const filter = { urls: ['*://www.googleapis.com'] };
session.defaultSession.webRequest.onBeforeRequest(filter, (details, callback) =&gt; {
  console.log('onBeforeRequest: ', details);
  callback({ cancel: true });
});
</code></pre></div>

<h3 dir="auto">Actual behavior</h3>
<p dir="auto">The callback is called for random URLs.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="onBeforeRequest:  { id: 1,
  method: 'GET',
  referrer: '',
  resourceType: 'mainFrame',
  timestamp: 1512654154551.9841,
  url: 'file:///Users/pronebird/apple/mail/build/index.html' }
onBeforeRequest:  { id: 4,
  method: 'GET',
  referrer: '',
  resourceType: 'mainFrame',
  timestamp: 1512654154564.2021,
  url: 'chrome-devtools://devtools/bundled/inspector.html?remoteBase=https://chrome-devtools-frontend.appspot.com/serve_file/@691bdb490962d4e6ae7f25c6ab1fdd0faaf19cd0/&amp;can_dock=&amp;toolbarColor=rgba(223,223,223,1)&amp;textColor=rgba(0,0,0,1)&amp;experiments=true' }"><pre class="notranslate"><code class="notranslate">onBeforeRequest:  { id: 1,
  method: 'GET',
  referrer: '',
  resourceType: 'mainFrame',
  timestamp: 1512654154551.9841,
  url: 'file:///Users/pronebird/apple/mail/build/index.html' }
onBeforeRequest:  { id: 4,
  method: 'GET',
  referrer: '',
  resourceType: 'mainFrame',
  timestamp: 1512654154564.2021,
  url: 'chrome-devtools://devtools/bundled/inspector.html?remoteBase=https://chrome-devtools-frontend.appspot.com/serve_file/@691bdb490962d4e6ae7f25c6ab1fdd0faaf19cd0/&amp;can_dock=&amp;toolbarColor=rgba(223,223,223,1)&amp;textColor=rgba(0,0,0,1)&amp;experiments=true' }
</code></pre></div>