[9.0] Fix fallback when Clipboard API is unavailable (#229531)#229654
Merged
kibanamachine merged 1 commit intoelastic:9.0from Jul 28, 2025
Merged
[9.0] Fix fallback when Clipboard API is unavailable (#229531)#229654kibanamachine merged 1 commit intoelastic:9.0from
kibanamachine merged 1 commit intoelastic:9.0from
Conversation
## Summary When accessing Kibana from an insecure browser context (e.g. `http://test.local`), some of Discover's "Copy to clipboard" actions have no effect (they don't copy data to the clipboard), despite showing a toast that says the data was copied. ## Analysis From the main Kibana Discover page, there are several different ways to copy to clipboard, with varying implementations: - ✅ Table Cell > Copy value of fields.type (`copyValueToClipboard`) - ✅ Table Header > Copy name (`copyColumnNameToClipboard`) -⚠️ Table Header > Copy column (`copyColumnValuesToClipboard`) -⚠️ Selected > Copy selection as text (`copyRowsAsTextToClipboard`) -⚠️ Selected > Copy documents as JSON (`copyRowsAsJsonToClipboard`) - ✅ Document sidebar > JSON > Copy to clipboard (`copyToClipboard`) The methods that **✅ work in both secure and insecure contexts** use [EUI `copyToClipboard`](https://github.com/elastic/eui/blob/6069ba651329bb2f65e6e5f8641b29e6b16198c6/packages/eui/src/services/copy/copy_to_clipboard.ts#L29-L58), which creates a hidden text element, fills it with data, selects it, and simulates the user invoking the "copy" action. The methods that **⚠️ only work in secure context** call `await window.navigator?.clipboard?.writeText(textToCopy);`. But since the [JavaScript Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API) is unavailable in that context (`window.navigator.clipboard` is undefined), this has no effect: it neither copies nor throws an exception. If an exception is thrown, it falls back to EUI `copyToClipboard` — but since no exception is thrown, it skips this fallback. This problem does not manifest in the default Kibana dev environment, `http://localhost:5601`, since [browsers consider `http://localhost` secure even though it doesn't use `https`](https://w3c.github.io/webappsec-secure-contexts/#localhost). ## Proposed solution This MR fixes that fallback (by throwing an exception if the Clipboard API is unavailable), and improves test coverage to check both when the Clipboard API is available and unavailable. It also fixes some false-positives in the existing tests, where some of the mocks were not being reset between each test, leading to some execution counters leaking from one test into the next. ## Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - this MR doesn't add or change user-facing text - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - this MR doesn't add new features - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - this MR adds tests - [x] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - this MR doesn't change any keys - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - this MR doesn't change any APIs - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - I don't have access to that - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - added release notes, but I don't have permission to add the label - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. - I don't have access to view that document ### Identify risks (no particular new risks) ## Release note Fixes issue where some of Discover's "Copy to clipboard" actions only worked when accessing Kibana in a secure browser context. (cherry picked from commit f43256f)
8 tasks
Contributor
💚 Build Succeeded
Metrics [docs]Async chunks
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport
This will backport the following commits from
mainto9.0:Questions ?
Please refer to the Backport tool documentation