title: Document not focused error when writing to clipboard using Clipboard API in chrome extension
body: <p>I'm working on an extension that takes takes a snapshot of a visible part of the page and copies it to the clipboard.  I decided to use the new <a href="https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API" rel="noreferrer">Clipboard API</a> to do that.
  The code that handles the capture and copy is located in the background.js of my extension.  Here's what it the relevant part looks like:</p>
  
  <pre><code>    chrome.tabs.captureVisibleTab(function(dataUrl) {
          convertToBlob(dataUrl).then((data) =&gt; {
              navigator.clipboard.write([
                  new ClipboardItem({
                      'image/png': data
                  })
              ]);
          });
      });
  </code></pre>
  
  <p>This action is triggered by a click on a widget that I inject into the page using <code>chrome.tabs.executeScript</code>.  I'm working in Chrome only.  However, every time I try it, I get this error:</p>
  
  <pre><code>Uncaught (in promise) DOMException: Document is not focused.
  </code></pre>
  
  <p>Initially, I assumed that the document I was capturing was not in focus, however it doesn't seem to be the case.  My <code>document.hasFocus()</code> was returning true.  Then I thought that for some reason which I can't fathom it wants the background.html to be focused.  So I ended up creating a custom background.html that contains an input field and prior to performing the navigator.clipboard access, I would focus and click on that input programmatically.  No dice.  EDIT:  I performed an actual page check and the background.html is indeed not focused, even though I dispatched the focus to it, which make sense.  What doesn't make sense is why this is happening since I'm supposed to capture stuff to clipboard in any context with this API.</p>
  
  <p>I did run a navigator.permissions query to see if clipboard-write access was granted, and it was.  </p>
  
  <p>At this point I'm out of ideas, does anyone have any recommendations?
  Thank you!
  Luka</p>