Adding text to clipboard (or pasting to cursor) in Chrome extension V3

Viewed 94

I'm building extension for Chrome using manifest V3. Interaction I'm trying to achieve is:

  1. User clicks a button in context menu.
  2. Extension communicates with the server and receives some string in response.
  3. User clicks another button in context menu and said string gets pasted where their cursor is.

I see two ways I could achieve it and I'm not sure which one makes more sense (or how to get either to work, really):

  • One would be to have said string put into clipboard and then have user access it with paste command.

  • Second would be to have a separate context menu button which upon pressing pastes the string where the cursor is.

Either solution would work for me, however I prefer one that asks for less permissions from user (I'm already accessing storage, requests and context menus). So far I was also able to avoid using background workers and event pages, which provided some convenience when working with context menus - I'd like to keep it that way, but I'd rather have my extensions actually working ^^

Unfortunately Chrome documentation is rather confusing, bordering on circular, when explaining how to achieve something like this, especially within Manifest V3. How do I go about it?

0 Answers
Related