Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clipboard work even in headless mode #1816

Open
asolntsev opened this issue May 26, 2022 · 6 comments
Open

Make clipboard work even in headless mode #1816

asolntsev opened this issue May 26, 2022 · 6 comments

Comments

@asolntsev
Copy link
Member

asolntsev commented May 26, 2022

The problem

Clipboard in Selenide work only in headful mode.
We can make it work in headless mode as well by using JavaScript instead of java.awt.Toolkit.

To set clipboard content:

window.clipboardData.setData('key', 'value')

To get clipboard content:

window.clipboardData.getData('key')

NB! Method getData() asks for permission. Need to find the webdriver option to suppress this dialog.

@asolntsev asolntsev added this to the 6.6.0 milestone May 26, 2022
@aakachurin
Copy link
Contributor

aakachurin commented May 30, 2022

I think it will help, it will accept all permissions
got it from browserstack

DesiredCapabilities caps = new DesiredCapabilities();
    // INIT CHROME OPTIONS
    ChromeOptions options = new ChromeOptions();
    Map<String, Object> prefs = new HashMap<String, Object>();
    Map<String, Object> profile = new HashMap<String, Object>();
    Map<String, Object> contentSettings = new HashMap<String, Object>();

    // SET CHROME OPTIONS
    // 0 - Default, 1 - Allow, 2 - Block
    contentSettings.put("notifications", 1);
    profile.put("managed_default_content_settings", contentSettings);
    prefs.put("profile", profile);
    options.setExperimentalOption("prefs", prefs);

    // SET CAPABILITY
    caps.setCapability(ChromeOptions.CAPABILITY, options);

@asolntsev
Copy link
Member Author

asolntsev commented Jun 6, 2022

@kachurinaa I haven't found any working solution for Firefox. :(
Probably it's possible with CDP?

@asolntsev asolntsev removed this from the 6.6.0 milestone Jun 6, 2022
asolntsev added a commit that referenced this issue Jun 6, 2022
Experiment failed: at least it doesn't work in Firefox.
And I didn't find proper Firefox preferences to enable clipboard access.
@aakachurin
Copy link
Contributor

aakachurin commented Jun 6, 2022

@kachurinaa I haven't found any working solution for Firefox. :( Probably it's possible with CDP?

Try to experiment with that


#---------------------------------------------------------------------------
# Prefs starting with "permissions."
#---------------------------------------------------------------------------

# 1-Accept, 2-Deny, Any other value: Accept
- name: permissions.default.image
  type: RelaxedAtomicUint32
  value: 1
  mirror: always

- name: permissions.delegation.enabled
  type: bool
  value: true
  mirror: always

- name: permissions.isolateBy.userContext
  type: RelaxedAtomicBool
  value: false
  mirror: always

- name: permissions.isolateBy.privateBrowsing
  type: RelaxedAtomicBool
  value: true
  mirror: always

or this

- name: dom.webnotifications.allowinsecure
  type: RelaxedAtomicBool
  value: false
  mirror: always

- name: dom.webnotifications.allowcrossoriginiframe
  type: RelaxedAtomicBool
  value: false
  mirror: always

- name: dom.webnotifications.enabled
  type: RelaxedAtomicBool
  value: true
  mirror: always

- name: dom.webnotifications.requireuserinteraction
  type: RelaxedAtomicBool
  value: true
  mirror: always

- name: dom.webnotifications.requireinteraction.enabled
  type: RelaxedAtomicBool
  value: @IS_NIGHTLY_BUILD@
  mirror: always

- name: dom.webnotifications.silent.enabled
  type: RelaxedAtomicBool
#if defined(MOZ_WIDGET_ANDROID)
  value: @IS_NIGHTLY_BUILD@
#else
  value: false
#endif
  mirror: always

like this

FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("dom.webnotifications.enabled", false);
WebDriver driver = new FirefoxDriver(ffprofile);

@asolntsev
Copy link
Member Author

@kachurinaa The permission is not the only problem. Firefox also says that navigator.clipboard or navigator.clipboard.readText is not defined.

@aakachurin
Copy link
Contributor

@asolntsev
Type "about:config" url in ff and switch/add attrs like that
clipboard=true
Its new privacy policy

@asolntsev
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants