cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Disable the "save address" popup in Chrome

Open magnattic opened this issue 1 year ago • 8 comments

What would you like?

When my tests fills out an address form with Chrome as the browser, the following prompt pops up: image

It would be great if this could be disabled altogether for cypress.

Why is this needed?

It overlaps the test window and has to be closed manually each time.

Other

During my google search, I found different ways this could be implemented:

Not sure if any of those actually work, but might be worth a try.

magnattic avatar Jan 27 '23 14:01 magnattic

We're also bumping into this stupid popup that prevents a page element from being clicked.

yktoo avatar Jan 30 '23 17:01 yktoo

Hi @magnattic , that does seem annoying! To be totally transparent, I don't see this issue being prioritized ahead of the extensive backlog. However we would definitely welcome external contributions that address this issue.

nagash77 avatar Jan 30 '23 17:01 nagash77

Until now I still haven't found a solution 🥲

anhtester avatar Aug 09 '23 10:08 anhtester

Same issue here, but with the "Save credit card" popup in Chrome.

sjmog avatar Oct 21 '23 14:10 sjmog

Now, I found this to work in Selenium Java.

ChromeOptions options = new ChromeOptions(); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.notifications", 2); prefs.put("autofill.profile_enabled", false); options.setExperimentalOption("prefs", prefs);

WebDriver driver = new ChromeDriver(options);

anhtester avatar Oct 23 '23 12:10 anhtester

This solves the issue for me:

// cypress.config.ts

import {defineConfig} from 'cypress'

export default defineConfig({
  e2e: {
    baseUrl: 'http://localhost:8080',
    setupNodeEvents(on, config) {
      // prettier-ignore
      on('before:browser:launch', (browser, launchOptions) => {
        if (browser.family === 'chromium' && browser.name !== 'electron') {
          // Disable Chrome's "Save address?" pop up
          launchOptions.preferences.default.autofill.profile_enabled = false

          // Disable Chrome's "Save password?" pop up
          launchOptions.preferences.default.credentials_enable_service = false
          launchOptions.preferences.default.profile.password_manager_enabled = false

          // Disable Chrome's "Save card?" pop up
          launchOptions.preferences.default.autofill.credit_card_enabled = false

          // Disable Chrome's "Show downloads when they're done" option
          launchOptions.preferences.default.download_bubble.partial_view_enabled = false

          return launchOptions
        }
      })

      return config
    },
  },
})

Would be great if Cypress applies these options by default.

But be careful! It seems chrome properties are cached. Try to comment out these modifications and console.log(launchOptions.preferences.default) – you will see these options are still applied. I tried cypress cache clear command and also re-install Chrome, but nothing helped. Maybe someone can suggest how to clear this cache?

sigerello avatar Apr 12 '24 16:04 sigerello

@sigerello Im trying your solution (copy paste), but getting error right away:

Cannot set properties of undefined (setting 'profile_enabled')
TypeError: Cannot set properties of undefined (setting 'profile_enabled')

Any ideas what Im missing ?

AlexSdet avatar May 03 '24 17:05 AlexSdet

@AlexSdet, it seems launchOptions.preferences.default.autofill is undefined in your case, while it should be an object. Have no idea why.

Try optionally initialize it:

launchOptions.preferences.default.autofill ??= {}
launchOptions.preferences.default.autofill.profile_enabled = false

Same for launchOptions.preferences.default.profile and launchOptions.preferences.default.download_bubble in case you will face into the similar issue for these properties.

sigerello avatar May 03 '24 17:05 sigerello