OpenSearch-Dashboards: [BUG] Share > Copy link broken in Safari

Describe the bug

Share > Copy link is broken in Safari. When you try to copy a link, you hear a sound and see a popup which says Copied, but nothing is copied into the clipboard.

To Reproduce Steps to reproduce the behavior:

  1. Go to Discover
  2. Click on Share > Copy link

Expected behavior Copy link should work in Safari.

OpenSearch Version 1.3.2 2.0.0

Dashboards Version 1.3.2 2.0.0

Plugins Default from the corresponding official Docker images

Host/Environment (please complete the following information):

  • OS: macOS Catalina 10.15.7
  • Safari 15.5 (15613.2.7.1.9, 15613)

Additional context

In Google Chrome 102.0.5005.61 it works without issues. In Firefox 101.0 it works without issues.

No logs in the Safari Developer Tools > Console, besides the two probably unrelated, which appear on page reload

[Error] Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy. (discover, line 352)
[Log] ^ A single error about an inline script not firing due to content security policy is expected! (bootstrap.js, line 43)

Related to #689.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 32 (11 by maintainers)

Most upvoted comments

I’d recommend creating a pull request and then you can get guidance based on the changes you’re making.

Thanks for the question - it depends 😆

Generally speaking every change should have a test associated with it. Sometimes a unit test is more than enough.

Another way you could approach this issue is by building a test case that fails and then making a fix that has the test passing.

Yes Leanne. The change I was proposing would go into security-dashboards-plugin where they manipulate the URL of the shareable.

  1. Before the manipulation happens, we get the parentNode and
  2. using Selection.removeAllRanges()[ref] we deselect it.
  3. Then the content is allowed to change and
  4. we select it back by creating a range, doing selectNode[ref], and then using addRange[ref] to select it.

I will pick this up @davidlago, please assign me. I will focus on closing my in review items & then pick this up in between.

This is not an issue of OUI. OuiCopy is correctly triggering document.execCommand('copy') but securityDashboards interferes with it.

  1. OuiCopy creates an invisible span, throws the URL being shared into it, selects it, and triggers “copy”.
  2. securityDashboards listens to the copy event to inject tenants into the URL being copied and it does this by attempting to change the text inside the invisible span using element.textContent.

The problem is that Firefox, Chrome, and Safari, each react differently. If some text in a node is “selected”:

  • Firefox: changing the node’s content using textContent does nothing; the original text remains in the node and it continues to be selected.
  • Chrome: the node’s content changes when setting textContent but also the result will be selected.
  • Safari: the node’s content changes when setting textContent but after that, nothing will be selected.

As a result, when the button to copy link is hit:

  • Firefox: security doesn’t get to update the URL and the original is copied.
  • Chrome: security gets to change the URL and the new one is copied.
  • Safari: since nothing is selected, nothing is copied.

This issue should be raised on security plugin. The appropriate solution would be for securityDashboards to change their listener to:

  1. find the parent node of the selection,
  2. deselect the text (so Firefox can change the node’s content),
  3. update the node’s content, and
  4. select the node’s content

When the listener is done, the copy would occur.