Make clipboard work even in headless mode

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kachurinaacommented, 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);
0reactions
kachurinaacommented, Jun 7, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 3 Selenium | Clipboard not working on headless ...
However, I still cannot confirm that it works on headless mode and mainly, my code got into multiple issue (since it was coded...
Read more >
Accessing clipboard content in headless mode - Google Groups
I am trying to access clipboard data in headless mode. I checked it in all channels available on Google and it says that...
Read more >
15986 (Shared clipboard is not working in headless mode)
Shared clipboard works find in both directions natively (i.e., when using the Virtualbox GUI directly), but in headless mode, using RDP, copying from...
Read more >
Using Headless Mode in the Java SE Platform - Oracle
To create a new Canvas component, use the Canvas class. Copy. Copied to Clipboard. Error: Could not Copy. final Canvas c = new...
Read more >
Give Chrome Browser Clipboard Permissions from Cypress Test
Using "Cypress.automation" command and Chrome Debugger Protocol we can access the clipboard text from the Cypress test to verify the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found