@@ -26,24 +26,13 @@ chrome.action.onClicked.addListener(async () => {
26
26
// `document.execCommand()`. To work around this, we'll create an offscreen
27
27
// document and pass it the data we want to write to the clipboard.
28
28
async function addToClipboard ( value ) {
29
- // This pattern ensures that the offscreen document exists before we try to
30
- // send it a message. If we didn't await the `hasDocument()` and
31
- // `createDocument()` calls, the `sendMessage()` call could send a message
32
- // before the offscreen document can register it's `runtime.onMessage`
33
- // listener.
34
- if ( await chrome . offscreen . hasDocument ( ) ) {
35
- console . debug ( 'Offscreen doc already exists.' ) ;
36
- } else {
37
- console . debug ( 'Creating a new offscreen document.' ) ;
38
-
39
- await chrome . offscreen . createDocument ( {
40
- url : 'offscreen.html' ,
41
- reasons : [ chrome . offscreen . Reason . CLIPBOARD ] ,
42
- justification : 'Write text to the clipboard.' ,
43
- } ) ;
44
- }
29
+ await chrome . offscreen . createDocument ( {
30
+ url : 'offscreen.html' ,
31
+ reasons : [ chrome . offscreen . Reason . CLIPBOARD ] ,
32
+ justification : 'Write text to the clipboard.' ,
33
+ } ) ;
45
34
46
- // Now that are sure we have an offscreen document, we can safely dispatch the
35
+ // Now that we have an offscreen document, we can dispatch the
47
36
// message.
48
37
chrome . runtime . sendMessage ( {
49
38
type : 'copy-data-to-clipboard' ,
0 commit comments