clipboard.writeText throws permission error in Bookmarklet
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
People
(Reporter: dogatmidnight, Unassigned)
References
(Blocks 1 open bug)
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:85.0) Gecko/20100101 Firefox/85.0
Steps to reproduce:
Install a bookmarklet like so
javascript:navigator.clipboard.writeText("foo")
Actual results:
After runnint the bookmarklet clipboard remains in its previous state. Developer console says "Clipboard write was blocked due to lack of user activation."
Expected results:
The code should execute since I (the "user") did activate the bookmarklet. On a side note: the same happens with an HTML page containing this code. According to the description of the Clipboard API, writeText should be allowed when run from the current tab. The code works in Safari and Chrome.
Comment 1•3 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.
Reporter | ||
Comment 2•3 years ago
|
||
Some more details:
- When I click on the bookmarklet in the toolbar, the error occrus
- When I define a keyboard shortcut to it (using Better Touch Tool, in this case), typing the keyboard shortcut runs the bookmarklet without error.
So it seems that Firefox considers a keyboard short cut "user activation" but not a mouse click.
Comment 3•3 years ago
|
||
I actually can't reproduce this... I am testing with the following bookmark:
javascript:(function(){ navigator.clipboard.writeText(new Date().toString()); alert("test"); })();void(0)
Reporter | ||
Comment 4•3 years ago
|
||
(In reply to Tom Schuster [:evilpie] from comment #3)
I actually can't reproduce this... I am testing with the following bookmark:
javascript:(function(){ navigator.clipboard.writeText(new Date().toString()); alert("test"); })();void(0)
Throws
Uncaught (in promise) DOMException: Clipboard write was blocked due to lack of user activation.
here. My dom.events.testing.asyncClipboard
preference is set to false
(which is the default).
When I set it to true
the code runs ok.
Comment 5•3 years ago
|
||
I tried bisecting this, but I got three impossible results so there might be some randomness involved.
Comment 6•3 years ago
|
||
In theory bug 1689853 should have fixed this. In my testing we call NotifyUserGestureActivation
.
Have you tried this in Firefox 86?
Reporter | ||
Comment 7•3 years ago
|
||
Apparently I was still on 85.0.1. After the upgrade to 86, it works ok. Also with my bookmarklet.
Updated•3 years ago
|
Description
•