<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>
<p dir="auto">When <code class="notranslate">ELECTRON_RUN_AS_NODE</code> is enabled, <code class="notranslate">setTimeout</code> is basically broken. It works the first time it's used, not the second time.</p>
<ul dir="auto">
<li><strong>Electron Version:</strong>
<ul dir="auto">
<li>Every version between 6.0.0 &amp; 9.0.0-beta12</li>
</ul>
</li>
<li><strong>Operating System:</strong>
<ul dir="auto">
<li>macOS 10.14.6 &amp; Ubuntu 18.04</li>
</ul>
</li>
<li><strong>Last Known Working Electron version:</strong>
<ul dir="auto">
<li>None</li>
</ul>
</li>
</ul>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">setTimeout should work consistently</p>
<h3 dir="auto">Actual Behavior</h3>
<p dir="auto">When <code class="notranslate">ELECTRON_RUN_AS_NODE</code> is enabled, <code class="notranslate">setTimeout</code> is basically broken. It works the first time it's used, not the second time.</p>
<h3 dir="auto">To Reproduce</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ git clone https://github.com/arantes555/electron-bug-settimeout.git
$ npm install
$ npm start"><pre class="notranslate">$ git clone https://github.com/arantes555/electron-bug-settimeout.git
$ npm install
$ npm start</pre></div>
<p dir="auto">This runs multiple times, with the current node &amp; with versions of electron from 6 to 9.<br>
For a given run, it prints <code class="notranslate">IT WORKED!</code> when <code class="notranslate">setTimeout</code> works normally, and nothing otherwise.</p>
<h3 dir="auto">Additional Information</h3>
<p dir="auto">Somehow, when wrapping the <code class="notranslate">setTimeout</code> in a <code class="notranslate">process.nextTick</code>, or a <code class="notranslate">setImmediate</code>, it works.</p>
<p dir="auto">This makes me thing that it's linked to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="174867157" data-permission-text="Title is private" data-url="https://github.com/electron/electron/issues/7079" data-hovercard-type="issue" data-hovercard-url="/electron/electron/issues/7079/hovercard" href="https://github.com/electron/electron/issues/7079">#7079</a> and to the activation of the uv loop in lib/common/init.ts .</p>
<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 <a href="https://www.github.com/electron/electron/issues">issue tracker</a> for a feature request that matches the one I want to file, without success.</li>
</ul>
<h3 dir="auto">Electron Version</h3>
<p dir="auto">13.1.9</p>
<h3 dir="auto">What operating system are you using?</h3>
<p dir="auto">Ubuntu</p>
<h3 dir="auto">Operating System Version</h3>
<p dir="auto">Ubuntu 20.04</p>
<h3 dir="auto">What arch are you using?</h3>
<p dir="auto">x64</p>
<h3 dir="auto">Last Known Working Electron version</h3>
<p dir="auto">11.0.5</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Prints the webpage</p>
<h3 dir="auto">Actual Behavior</h3>
<p dir="auto">Not printing, no error.</p>
<h3 dir="auto">Testcase Gist URL</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Additional Information</h3>
<p dir="auto">I found issue tracker with same problem for version 5 <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="439703769" data-permission-text="Title is private" data-url="https://github.com/electron/electron/issues/18123" data-hovercard-type="issue" data-hovercard-url="/electron/electron/issues/18123/hovercard" href="https://github.com/electron/electron/issues/18123">#18123</a> It is working fine in 11.0.5 but no success with 12 or 13 branch.</p>
<p dir="auto">Example:<br>
`let printersInfo = printWindow.webContents.getPrinters();<br>
let printer = printersInfo.filter(printer =&gt; printer.isDefault === true)[0];<br>
const options = {<br>
silent: true,<br>
deviceName: printer.name<br>
}</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        printWindow.webContents.print(options, () =&gt; {
            printWindow = null;
        });`"><pre class="notranslate"><code class="notranslate">        printWindow.webContents.print(options, () =&gt; {
            printWindow = null;
        });`
</code></pre></div>