title: Python selenium download pdf with headless and plugins.always_open_pdf_externally
body: <p>I need to download a pdf, I use headless so the browser doesn't open, and the pdf is in a view, so I used the <code>"plugins.always_open_pdf_externally" parameter: True</code>.</p>
  
  <p>To not render the browser I use the <code>options.add_argument ("- headless")</code> parameter.</p>
  
  <p>If I comment on <code>options.add_argument ("- headless")</code> the pdf download usually happens, but if I leave it enabled it doesn't work.</p>
  
  <p>How can I solve this problem?</p>
  
  <p>parameters:</p>
  
  <pre><code>options = Options()
  options.add_argument("--headless")
  options.add_argument("--window-size=1920,1080")
  options.add_experimental_option("excludeSwitches", ["enable-automation"])
  options.add_experimental_option('useAutomationExtension', False)
  
  appState = {
      "recentDestinations": [
          {
              "id": "Save as PDF",
              "origin": "local"
          }
      ],
      "selectedDestinationId": "Save as PDF",
      "version": 2
  }
  
  profile = {"plugins.plugins_list": [{"enabled": False, "name": "Chrome PDF Viewer"}], # Disable Chrome's PDF Viewer
                 "download.extensions_to_open": "applications/pdf",
              #    "plugins.always_open_pdf_externally": True,
                 "printing.print_preview_sticky_settings.appState": json.dumps(appState)}
  
  options.add_experimental_option("prefs", profile)
  
  driver = webdriver.Chrome(chrome_options=options, executable_path=r'D:\Mega\Raiz\Dados_brcaptura\chromedriver.exe')
  print ("Headless Chrome Initialized")
  
  params = {'behavior': 'allow', 'downloadPath': r'C:\Users\dieinimy\Downloads'}
  driver.execute_cdp_cmd('Page.setDownloadBehavior', params)```
  </code></pre>