Closed Bug 1693750 Opened 3 years ago Closed 3 years ago

clipboard.writeText throws permission error in Bookmarklet

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 85
defect

Tracking

()

RESOLVED DUPLICATE of bug 1689853

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.

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.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

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.

Blocks: 1619251
See Also: → 1694013

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)

(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.

I tried bisecting this, but I got three impossible results so there might be some randomness involved.

In theory bug 1689853 should have fixed this. In my testing we call NotifyUserGestureActivation.

Have you tried this in Firefox 86?

Flags: needinfo?(dogatmidnight)

Apparently I was still on 85.0.1. After the upgrade to 86, it works ok. Also with my bookmarklet.

Flags: needinfo?(dogatmidnight)
Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.