title: Allow Firefox AddOn to focus window
body: <p>I'm trying to write a Firefox AddOn that allows the user to quickly bring a specific open window to the front. While doing research on how to focus windows, I learned that browsers heavily restrict this to avoid misuse. Which I totally support if it is not intended by the user. In my case the user would install the AddOn to explicitly have this functionality, so focusing windows would be intended by the user.</p>
  <p>The classic way to do this is <code>Window.focus()</code> but even the Mozilla docs say, that the success of this operation depends on the configuration of the user's browser.</p>
  <blockquote>
  <p>Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns. - <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/focus" rel="nofollow noreferrer">Source</a></p>
  </blockquote>
  <p>In my browser (Firefox 94 on Ubuntu) it doesn't work.</p>
  <p>I also read that setting <code>dom.disable_window_flip</code> to <code>true</code> in <code>about:config</code> will enable <code>Window.focus()</code> but it didn't - and it wouldn't be a feasible approach for an AddOn.</p>
  <p>Firefox AddOns use a <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#api_permissions" rel="nofollow noreferrer">permission system</a> and my expectation would be that there must be a permission that allows focusing windows for this specific AddOn. Unfortunately the permissions aren't very well documented and I couldn't find the right one via trial and error.</p>
  <p>Most of the scarce information on focusing windows through AddOns that I found on the web was posted 5 to 10 years ago and doesn't work anymore.</p>
  <p>I tried several approaches like calling <code>browser.windows.update(tabId, { focused: true })</code> from the popup script (which I have a <a href="https://stackoverflow.com/questions/69890326/browser-windows-get-cant-access-dead-object">different issue</a> with). I also tried to inject a content script that calls <code>Window.focus()</code> when asked to by a message from the popup script. None of those worked.</p>
  <p>So my first question would be: is there any way today (2021, Firefox 94) to allow AddOns to bring a window to front?</p>
  <p>And if so: can anyone please show me how?</p>
  <p>Thanks in advance!</p>