title: Selenium node JavaScript disable downloads
body: <p>Hi my selenium chromedriver in node automatically downloads files.
  I want to disable automatically downloads,</p>
  <p>therefor I found many threads  for python with a solution to set download_restrictions to  3, but in JS is no experimental settings I guess, and userPreferences seems to be the wrong place.</p>
  <p>Someone know how to disable automatically downloads in a headless chrome in node.</p>
  <p>Src:
  <a href="https://stackoverflow.com/questions/59491516/disable-all-downloads-with-chromedriver-and-selenium">Disable all downloads with ChromeDriver and Selenium</a></p>
  <p><a href="https://chromeenterprise.google/policies/?policy=DownloadRestrictions" rel="nofollow noreferrer">https://chromeenterprise.google/policies/?policy=DownloadRestrictions</a>
  <a href="https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup" rel="nofollow noreferrer">https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup</a></p>
  <p>my example code, download directory seems to be working</p>
  <pre><code>import { Builder, Capabilities } from 'selenium-webdriver';
  import * as Chrome from 'selenium-webdriver/chrome.js'
  
  export async function getDriver() {
    const service = new Chrome.ServiceBuilder(&quot;./selenium/chromedriver&quot;);
    const chromeOpts = await new Chrome.Options()
        .addArguments(&quot;--disable-infobars&quot;)
        .addArguments(&quot;--headless&quot;)
        .setUserPreferences({
          &quot;download_restrictions&quot; : 3
        })
  
    const driver = new Builder()
        .withCapabilities(Capabilities.chrome())
        .setChromeService(service)
        .setChromeOptions(chromeOpts)
        .build();
  
    return driver;
  }
  
  const driver = await getDriver()
  driver.get(&quot;http://www.africau.edu/images/default/sample.pdf&quot;)
  </code></pre>