protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Chrome sendChromiumCommand 'Page.setDownloadBehavior' failing - UnsupportedOperationError

Open jonsamwell opened this issue 6 years ago • 13 comments

Bug report

  • Node Version: 10.16.0
  • Protractor Version: 5.4.2
  • Angular Version: 8
  • Browser(s): Chrome (headless / normal)
  • Operating System and Version Windows 10
  • Your protractor configuration file
capabilities: {
    browserName: 'chrome',

    chromeOptions: {
      args: useHeadlessBrowser ? ["--headless", "--window-size=1920,1080"] : undefined,
      useAutomationExtension: false,

      // Set download path and avoid prompting for download even though
      // this is already the default on Chrome but for completeness
      // https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc
      prefs: {
        "download": {
          "prompt_for_download": false,
          "directory_upgrade": true,
          "default_directory": downloadDirectory,
          "download_directory": downloadDirectory,
          "download_dir": downloadDirectory,
          "download_restrictions": 0,
        }
      }
    }
  },

Before any tests run I send the below command to Chrome to enable file downloads in headless Chrome

    // returns full path
    const downloadDirectory = Utils.getTempDirectoryPath();

    Utils.log(`Setting Chrome download behaviour to directory ${downloadDirectory}`);
    browser.driver.sendChromiumCommand('Page.setDownloadBehavior', {
      behavior: 'allow',
      downloadPath: downloadDirectory
    });

This has stopped working on Chrome 74+ with the error.

UnsupportedOperationError: POST /session/ac771ec3019f7b4c7191e2c9ae2b2056/chromium/send_command

We are unable to run test on Chrome 74 now and cannot get any of our file download tests to work as headless Chrome is unable to download a file with issuing the above command.

Is there any other suggested way to enable file downloads in headless Chrome without issuing the above command?

jonsamwell avatar Aug 06 '19 02:08 jonsamwell

Even I am facing the same issue with same error UnsupportedOperationError: POST /session/f397ed9f1895f4ff384b4c57fab31580/chromium/send_command

Node Version: v10.15.1 Protractor Version: 5.4.2 Browser(s): Chrome (headless / normal) - 76.0.3809.87 Operating System and Version Windows 10

janilkumarreddy avatar Aug 06 '19 12:08 janilkumarreddy

Also having this issue.

MatthewMSaucedo avatar Aug 09 '19 14:08 MatthewMSaucedo

Any movement on this?

jonsamwell avatar Aug 21 '19 01:08 jonsamwell

I have run into this issue also.

oscarguinane avatar Sep 09 '19 17:09 oscarguinane

@jonsamwell, as i see you're using chrome 76, the capabilities set for chrome doesn't work as it expects chrome options in W3C mode.

By Default, from chrome 74+, it strictly follows W3C compliant commands.

harsha509 avatar Sep 10 '19 13:09 harsha509

@Harsha509 what does this mean in practice?

jonsamwell avatar Sep 10 '19 23:09 jonsamwell

Hi @jonsamwell ,

In practiece chromeOptions{} may not work as now chrome 74+ expects options to be in w3c format -> goog:chromeOptions{}

you can refer to w3c doc for this change https://www.w3.org/TR/webdriver/#extensions-0 example 5:

You can give it a try by turning off W3C in chromeOptions: chromeOptions:{ 'args':[...], 'w3c': false, }

Thanks!

harsha509 avatar Sep 18 '19 08:09 harsha509

I made it work using this versions:

  • Protractor: 5.4.2
  • Selenium standalone server: 3.141.59
  • Chrome: 77.0.3865.40

I launched Chome in headlles way and everything is fine. Actually, it seems like browser.driver.sendChromiumCommand(...) configuration is not longer necessary. I deleted it and everything works fine for me.

I did not try setting "w3c":false but with the versions I mention and deleting the configuration, everything seems to work.

BZaldua avatar Sep 18 '19 09:09 BZaldua

I made it work using this versions:

  • Protractor: 5.4.2
  • Selenium standalone server: 3.141.59
  • Chrome: 77.0.3865.40

I launched Chome in headlles way and everything is fine. Actually, it seems like browser.driver.sendChromiumCommand(...) configuration is not longer necessary. I deleted it and everything works fine for me.

I did not try setting "w3c":false but with the versions I mention and deleting the configuration, everything seems to work.

Hi @BZaldua , can I check how did you define the default download directory without sending the chromium command?

timothyjmtan avatar Sep 24 '19 07:09 timothyjmtan

@timothyjmtan

var path = require('path');
...

exports.config = {
   seleniumAddress: 'http://localhost:4444/wd/hub',
   capabilities: {
      browserName: 'chrome',
        chromeOptions: {
            args: [
                '--headless', '--window-size=1280,720', '--no-sandbox'
            ],
            prefs: {
                download: {
                    'prompt_for_download': false,
                    'directory_upgrade': true,
                    'default_directory': path.resolve('./test/downloads/')
                }
            }
        }
    },
   specs: [**/*.spec.js'],
   framework: 'jasmine2',
   plugins: [],
   onPrepare: function () {
        browser.protractorImageComparison = new ProtractorImageComparison({...});
        ...
   }
}

BZaldua avatar Sep 24 '19 08:09 BZaldua

Thanks @BZaldua !

timothyjmtan avatar Sep 24 '19 08:09 timothyjmtan

Just following up here, @BZaldua's versions worked for me also.

oscarguinane avatar Sep 27 '19 19:09 oscarguinane

Using chromedriver from this link and a chromium binary from this link I was able to use the driver.execute_cdp_cmd method.

params = {'behavior': 'allow', 'downloadPath': path}
driver.execute_cdp_cmd('Page.setDownloadBehavior', params)

vmgustavo avatar Oct 20 '21 20:10 vmgustavo