Open patrickkettner opened 7 months ago
@patrickkettner Just a heads up that we will be discussing this issue in this week's EditingWG meeting which is scheduled on Thursday 8am PST. Link to the meeting: https://www.w3.org/groups/wg/webediting/calendar/
thanks! I will be in attendance.
How would the API work for web pages when used in service worker? There is no user activation or anything, so clipboard.read(), as an example, wouldn't ever work.
@smaug---- great question! That is correct, without user activation, it wouldn't work. So it would only be useful in situations where the user activation could happen outside of the service worker, like in the case of Web Extensions. The base of extensions in manifest v3 is a standard service worker.
But user activation is defined to be bound to Window object, and clipboard requires that. I'm missing to see how this could work.
On the web, it wouldn't. In a Web Extension, there is a separate permissions model for the user to knowingly allow for the action to take place and way to receive user inputs. A common usecase is an extension that listens for a command key or click of the action button to copy a shortened/templated/more-than-just-the-standard URL of the currently viewed tab.
deleted my previous comment as it was not related to service workers
But Web Extensions aren't part of the web platform. See for example https://github.com/whatwg/html/issues/8362#issuecomment-1271048474 (and which is why https://github.com/w3c/webextensions/issues/287 was filed)
The Web Editing Working Group just discussed Support navigator clipboard inside SW
.
Hiya folks, I work in devrel for Chrome Extensions. I have been helping folks migrate to manifest v3, and one thing that has come up a number of times in clipboard access. In the past, a background page made it easy to use standard DOM interactions with the clipboard. But with extensions moving to a service worker based background in manifest v3, it becomes a lot more complicated. While there are workarounds¹, it would greatly reduce complexity of a number of extensions if the platform had access to navigator.clipboard.
In practice, I believe this would mean exposing Clipboard onto WorkerNavigator, as that is what is inherited by the service worker.
chrome.offscreen
, which gives the developer access to a HTML document they provide that is rendered offscreen. To copy the clipboard, you need to create the offscreenDocument singleton, send an event over RPC to the HTML document they provide, which listens for the event, then executes document.execCommand (offscreen documents don't support navigator.clipboard as of now), then responds with another RPC back to the service worker with the data they requested, and then shut down the offscreenDocument. Its a lot of indirection.