<p dir="auto">The title says it all. I'd like if <code class="notranslate">fetch</code> could also open local files, just like the browser can if the origin ist <code class="notranslate">file://</code>.</p>
<p dir="auto">There is even a test that checks that this does not work here: </p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/denoland/deno/blob/e568ddf99687f635abe931c1eff2b8b37be3bc54/cli/tests/unit/fetch_test.ts#L14-L20">deno/cli/tests/unit/fetch_test.ts</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 14 to 20
      in
      <a data-pjax="true" class="commit-tease-sha" href="/denoland/deno/commit/e568ddf99687f635abe931c1eff2b8b37be3bc54">e568ddf</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="L14" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="14"></td>
          <td id="LC14" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">await</span> <span class="pl-en">assertThrowsAsync</span><span class="pl-kos">(</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L15" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="15"></td>
          <td id="LC15" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">&gt;</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L16" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="16"></td>
          <td id="LC16" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">await</span> <span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-s">"file:///"</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L17" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="17"></td>
          <td id="LC17" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-kos">}</span><span class="pl-kos">,</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L18" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="18"></td>
          <td id="LC18" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-smi">TypeError</span><span class="pl-kos">,</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L19" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="19"></td>
          <td id="LC19" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-s">"not supported"</span><span class="pl-kos">,</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L20" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="20"></td>
          <td id="LC20" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">Allowing <code class="notranslate">file://</code> could profit any library or script that really just needs the contents of a file and doesn't really care where it is.... just like <code class="notranslate">deno run</code> in fact.</p>
<p dir="auto">At this moment, you'd have to implement some kind of wrapper.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="async function readTextFile(url: URL): Promise&lt;string&gt; {
    if (url.protocol === 'file:' &amp;&amp; typeof Deno.readTextFile !== 'undefined') {
        return await Deno.readTextFile(url.pathname)
    } else {
        const response = await fetch(url)
        return await response.text()
    }
}"><pre class="notranslate">async <span class="pl-k">function</span> <span class="pl-s1">readTextFile</span><span class="pl-kos">(</span><span class="pl-s1">url</span>: <span class="pl-c1">URL</span><span class="pl-kos">)</span>: <span class="pl-v">Promise</span><span class="pl-c1">&lt;</span><span class="pl-s1">string</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-c1">if</span> <span class="pl-kos">(</span><span class="pl-s1">url</span><span class="pl-kos">.</span><span class="pl-s1">protocol</span> <span class="pl-c1">===</span> <span class="pl-s">'file:'</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-k">typeof</span> <span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-c1">readTextFile</span> <span class="pl-c1">!==</span> <span class="pl-s">'undefined'</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-k">await</span> <span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-en">readTextFile</span><span class="pl-kos">(</span><span class="pl-s1">url</span><span class="pl-kos">.</span><span class="pl-c1">pathname</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
        <span class="pl-k">const</span> <span class="pl-s1">response</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-s1">url</span><span class="pl-kos">)</span>
        <span class="pl-k">return</span> <span class="pl-k">await</span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">text</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">There are a few things interesting points to look out for:</p>
<ul dir="auto">
<li>Error code mapping aka: 404 = not found/file does not exist, 403 = unauthorized/--allow-read-missing/filemod</li>
<li>Partial request?</li>
<li>Post/Put request?</li>
</ul>
<p dir="auto">Hello,<br>
I was trying to debug a small app and was surprised when <code class="notranslate">console.log</code> did not print the private properties of a class. I ran the code in Chrome and it printed the private property. So at least there is an inconsistency between Chrome and Deno. I would say private properties should be logged by <code class="notranslate">console.log</code> and friends, i.e.: <code class="notranslate">debug</code>, <code class="notranslate">warn</code>, <code class="notranslate">error</code> and <code class="notranslate">trace</code>. It's very useful for debugging purposes. Is this intended behavior?</p>
<h2 dir="auto">Example</h2>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Test {
  #q = &quot;qwe&quot;
  a = &quot;asd&quot;
}
let t = new Test()
console.log(t)"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Test</span> <span class="pl-kos">{</span>
  #q <span class="pl-c1">=</span> <span class="pl-s">"qwe"</span>
  <span class="pl-c1">a</span> <span class="pl-c1">=</span> <span class="pl-s">"asd"</span>
<span class="pl-kos">}</span>
<span class="pl-k">let</span> <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Test</span><span class="pl-kos">(</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-s1">t</span><span class="pl-kos">)</span></pre></div>
<h2 dir="auto">Deno Result</h2>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/970403/98456457-81415500-2143-11eb-9cb2-de99f1e2430a.png"><img src="https://user-images.githubusercontent.com/970403/98456457-81415500-2143-11eb-9cb2-de99f1e2430a.png" alt="image" style="max-width: 100%;"></a></p>
<h2 dir="auto">Chrome Result</h2>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/970403/98456426-f5c7c400-2142-11eb-82d2-7737862fe53c.png"><img width="237" alt="image" src="https://user-images.githubusercontent.com/970403/98456426-f5c7c400-2142-11eb-82d2-7737862fe53c.png" style="max-width: 100%;"></a></p>