-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Bug-1773681 Showing Paste button for navigator.clipboard.readText() #42263
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
base: main
Are you sure you want to change the base?
Bug-1773681 Showing Paste button for navigator.clipboard.readText() #42263
Conversation
|
This pull request has merge conflicts that must be resolved before it can be merged. |
…or.clipboard.readText()
|
Preview URLs
Flaws (1)Note! 3 documents with no flaws that don't need to be listed. 🎉 URL:
External URLs (1)URL:
(comment last updated: 2026-01-02 17:59:29) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be aware that this change does not accurately reflect how to work with the clipboard in extensions across browsers. Specifically, Chrome does not expose navigator.clipboard to extension service workers and offscreen documents cannot access navigator.clipboard due to the API's document focus requirements. As a result, Chrome extensions have to fall back to using the deprecated document.execCommand() APIs in an offscreen document or using navigator.clipboad in a different context (content scripts or extension pages).
While I strongly feel that we should target cross-browser extension develpment, I don't want to block this PR or require a rewrite at the moment. That said, if we don't integrate cross-browser develpment in this revision, we may need to revise this article again in the coming months. @rebloor, do you have any preferences on how we should proceed?
…d.readText()' of ssh://github.com/rebloor/content into Bug-1773681-Showing-Paste-button-for-navigator.clipboard.readText()
…or.clipboard.readText()
|
@dotproto I've added the additional Chrome information. I'd checked for any additional information prior to making the changes and couldn't find anything suggesting there were any further considerations. Do you have a link to any Chrome documentation? |
Rob--W
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the feedback below, also some browser compatibility notes:
- clipboardWrite permission enables writing to the clipboard from all extension contexts and content scripts in Firefox. In Chrome and Safari, the clipboardWrite permission is only supported in extension contexts (not content scripts).
- clipboardRead permission enables writing to the clipboard from all extension contexts and content scripts in Firefox. In Chrome, the clipboardRead permission is only supported in extension contexts (not content scripts). Safari does not support the clipboardRead permission at all.
|
|
||
| > [!NOTE] | ||
| > The `clipboard-write` permission name is not supported in Firefox, only Chromium browsers. | ||
| The Clipboard API write methods {{domxref("Clipboard.readText", "navigator.clipboard.readText()")}} and {{domxref("Clipboard.writeText", "navigator.clipboard.writeText()")}} write arbitrary content to the clipboard. The methods are available from a secure context after the extension's user has performed {{Glossary("Transient Activation","transient activation")}}. However, with the [`"clipboardWrite"` permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#clipboardwrite) the methods are available without transient activation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- readText -> write.
- available -> rephrased, because "methods are available" could imply that the API method is missing if the conditions have not been met. However, the methods are always there, they just reject if the requirements have not been met.
| The Clipboard API write methods {{domxref("Clipboard.readText", "navigator.clipboard.readText()")}} and {{domxref("Clipboard.writeText", "navigator.clipboard.writeText()")}} write arbitrary content to the clipboard. The methods are available from a secure context after the extension's user has performed {{Glossary("Transient Activation","transient activation")}}. However, with the [`"clipboardWrite"` permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#clipboardwrite) the methods are available without transient activation. | |
| The Clipboard API methods {{domxref("Clipboard.write", "navigator.clipboard.write()")}} and {{domxref("Clipboard.writeText", "navigator.clipboard.writeText()")}} write arbitrary content to the clipboard. The methods are available from a secure context, but are only functional after the extension's user has performed {{Glossary("Transient Activation","transient activation")}}. However, with the [`"clipboardWrite"` permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#clipboardwrite) transient activation is not required. |
Please apply a similar edit to the other section.
| } | ||
| ``` | ||
|
|
||
| ### Using execCommand() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you restore the full examples here? They are more helpful than the replacements that you added. The original explanation is more tutorial-like and a walkthrough with all relevant details (including a highlight of the difference of running with and without user interaction).
And although execCommand has been deprecated, I do not see it going away realistically, due to its long history, prevalent use, and supporting capabilities that are not available in the clipboard API.
For that reason, instead of rewriting the example, I'd suggest to restore the execCommand examples.
|
|
||
| ## Changes for add-on developers | ||
|
|
||
| - When using [navigator.clipboard.readText()](/en-US/docs/Web/API/Clipboard/readText) or [navigator.clipboard.read()](/en-US/docs/Web/API/Clipboard/read) without the `clipboardRead` permission, a clipboard paste button is displayed to obtain user confirmation. If the extension has `clipboardRead` permission, it reads the clipboard data without user confirmation. For more information on working with the clipboard in extensions, see [Interact with the clipboard](/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard). ([Firefox bug 1773681](https://bugzil.la/1773681)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - When using [navigator.clipboard.readText()](/en-US/docs/Web/API/Clipboard/readText) or [navigator.clipboard.read()](/en-US/docs/Web/API/Clipboard/read) without the `clipboardRead` permission, a clipboard paste button is displayed to obtain user confirmation. If the extension has `clipboardRead` permission, it reads the clipboard data without user confirmation. For more information on working with the clipboard in extensions, see [Interact with the clipboard](/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard). ([Firefox bug 1773681](https://bugzil.la/1773681)) | |
| - When using [navigator.clipboard.readText()](/en-US/docs/Web/API/Clipboard/readText) or [navigator.clipboard.read()](/en-US/docs/Web/API/Clipboard/read) without the `clipboardRead` permission, a clipboard paste button is displayed to obtain user confirmation. If the extension has `clipboardRead` permission, it continues to read the clipboard data without user confirmation, as before. For more information on working with the clipboard in extensions, see [Interact with the clipboard](/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard). ([Firefox bug 1773681](https://bugzil.la/1773681)) |
…ance and add additional compatibility details.
| In Firefox: | ||
|
|
||
| - The availability of the Clipboard API read methods on the user's response to a paste prompt became available in Firefox 127. Before that, the methods were only available when the extension set the `"clipboardRead"` permission. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - The availability of the Clipboard API read methods on the user's response to a paste prompt became available in Firefox 127. Before that, the methods were only available when the extension set the `"clipboardRead"` permission. | |
| - The availability of the Clipboard API read methods on the user's response to a paste prompt became available in Firefox 127 in web pages, but only in extensions from Firefox 147. In content Before that, the methods were only available when the extension set the `"clipboardRead"` permission. |
| Two permissions enable an extension to interact with the clipboard: | ||
|
|
||
| - `clipboardWrite` | ||
| - : Write to the clipboard using {{DOMxRef("Clipboard.write()")}}, {{DOMxRef("Clipboard.writeText()")}}, `document.execCommand("copy")` or `document.execCommand("cut")` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep mention of execCommand. The permissions still unlock functionality on these APIs.
|
This pull request has merge conflicts that must be resolved before it can be merged. |
…or.clipboard.readText()
Description
This change addresses the dev-docs-needed requirement of Bug 1773681 Enable showing "Paste" button for
navigator.clipboard.readText()when called from Addons which don't haveclipboardReadpermssion.The changes include:
document.execCommandmethods were removed.document.execCommandmethods.Related issues and pull requests
Notes in the BCD updated in mdn/browser-compat-data#28587