What is the future of clipboard reading in the background with manifest v3?

1,025 views
Skip to first unread message

Deliaz

unread,
Feb 20, 2021, 5:18:09 AM2/20/21
to Chromium Extensions
I own the extension called Clipboard History Pro (ajiejmhbejpdgkkigpddefnjmgcbkenk). 
The main purpose of which - is to be a high-quality clipboard manager, used by 100,000+ users. 

In order to monitor the clipboard, it constantly runs  `document.execCommand("paste")` in the background page. 
However, with manifest v3 I am not sure it will be possible anymore. Am I right? 

Does it mean that extension is going to lose its core feature? 
Is there any possible workaround? 

Thanks, 
Denis. 

PhistucK

unread,
Feb 20, 2021, 9:11:40 AM2/20/21
to Deliaz, Chromium Extensions
You can have a background tab always open as an alternative approach. Not pretty, but should work.

PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/57a059f7-c133-4c81-a2ba-dfa5742e4193n%40chromium.org.

wOxxOm

unread,
Feb 20, 2021, 9:20:38 AM2/20/21
to Chromium Extensions, PhistucK, Chromium Extensions, d3l...@gmail.com
It's tracked in https://crbug.com/1160302

Another workaround, used by many extensions currently for things like a complex UI or to ask for media permissions, is to add an iframe that points to an html file exposed via web_accessible_resources in manifest.json. The html file would load a js file which should be able to use both the classic DOM methods for clipboard as well as navigator.clipboard and all `chrome` API granted to the extension. Chrome explicitly allows such extension iframes even on pages with CSP that forbids framing. Anyway the page can remove it as it's a normal DOM element so don't rely on it being always present but add it as necessary.

Deliaz

unread,
Feb 20, 2021, 9:31:37 AM2/20/21
to Chromium Extensions, wOxxOm, PhistucK, Chromium Extensions, Deliaz
Thank you for the ideas, will track related crbug. 

@wOxxOm, do you mean inject iframes in each tab? I didn't get this part. 

wOxxOm

unread,
Feb 20, 2021, 9:43:07 AM2/20/21
to Chromium Extensions, d3l...@gmail.com, wOxxOm, PhistucK, Chromium Extensions
In your case one tab is enough because the classic DOM execCommand should work in backgrounded tabs just fine as long as Chrome doesn't freeze or discard it. So the idea is to ensure at least one iframe always runs somewhere. It can be achieved by using chrome.runtime.connect() inside the iframe and listening to onDisconnect in the background script so when it triggers you would create an iframe somewhere else. In case there are no web tabs you would have to open a new tab, unfortunately.

Deliaz

unread,
Feb 20, 2021, 9:47:42 AM2/20/21
to Chromium Extensions, wOxxOm, Deliaz, PhistucK, Chromium Extensions
I see, thanks! Sounds feasible but tricky.
Will do some tests.

It is sad there is no simple Chromium API for that. 

guest271314

unread,
Feb 21, 2021, 10:37:21 AM2/21/21
to Chromium Extensions, d3l...@gmail.com, wOxxOm, PhistucK, Chromium Extensions
What is the purpose of running 

> `document.execCommand("paste")`

constantly?

Chromium and Chrome now support asynchronous clipboard operations. When permission is granted once it is possible to read and write to clipboard across browsing contexts at the same browser, different browsers, and, or using browser and OS methods.

Deliaz

unread,
Feb 21, 2021, 10:49:35 AM2/21/21
to guest271314, Chromium Extensions, wOxxOm, PhistucK
Do you mean this API?

Unfortunately, it is not accessible to service workers. 

guest271314

unread,
Feb 21, 2021, 12:44:10 PM2/21/21
to Chromium Extensions, d3l...@gmail.com, Chromium Extensions, wOxxOm, PhistucK, guest271314
Yes. I was not aware that the API was not available in Workers. The using the approach described by @wOxxOm should meet the requirement. User gesture is (initially) required for async read/write. An example of using a parent HTML page (index.html) and two separate <iframe> elements to communicate between the frames (and with parent page) via write() and read() https://plnkr.co/edit/1HsvQh08tYb24810?preview.

guest271314

unread,
Feb 21, 2021, 12:47:41 PM2/21/21
to Chromium Extensions, guest271314, d3l...@gmail.com, Chromium Extensions, wOxxOm, PhistucK
Actually I dd not use clipboard in that version. This is the gist I was referring to https://gist.github.com/guest271314/04a539c00926e15905b86d05138c113c

guest271314

unread,
Feb 21, 2021, 12:52:48 PM2/21/21
to Chromium Extensions, guest271314, d3l...@gmail.com, Chromium Extensions, wOxxOm, PhistucK
In the gist await navigator.clipboard.writeText() will throw if empty string is not passed.

You should be able to use either approach, that is, communicate using postMessage() or clipboard with a parent HTML page and N <iframe>'s.

Crystal N

unread,
Feb 21, 2021, 1:21:26 PM2/21/21
to guest271314, Chromium Extensions, d3l...@gmail.com, wOxxOm, PhistucK
These people are hacking my account to acieve information thank u for using my email to give me proof to bring you to justice

guest271314

unread,
Feb 21, 2021, 2:19:37 PM2/21/21
to Chromium Extensions, cryst...@gmail.com, Chromium Extensions, d3l...@gmail.com, wOxxOm, PhistucK, guest271314
Who precisely are "these people"?

I do not know what the issue is that you are describing?

Reply all
Reply to author
Forward
0 new messages