title: Given a moz-extension:// URL opened by bookmark, how can I switch to tab using extension code?
body: <p>This is related to some other questions I am working on.</p>
  
  <p>Say, for whatever reason, a user has bookmarked a page (call it <code>pageURL</code> of the pattern <code>moz-extensions://MY-OWN-WEBEXT-ID/*</code>) intended to be opened from a browser action context menu, and opened it in a tab, then opened many other tabs and possibly other windows.  User knows the extension tab exists somewhere and doesn't want to keep opening new bookmarks, and so wants to use the add-on's browser action context menu to find the extension page's tab.  Likewise, I don't want my add-on to open a duplicate tab.</p>
  
  <p>The problem, since the add-on did not create the tab (a bookmark did), I have no tab ID to pass to <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/update" rel="nofollow noreferrer"><code>browser.tabs.update( WebExtTab.id, { active: true } )</code></a> or window ID to pass to <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/windows/update" rel="nofollow noreferrer"><code>browser.windows.update( WebExtWindow.id, { focused: true } )</code></a>.  (<code>WebExtWindow</code> referring to a WebExtensions <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/windows/Window" rel="nofollow noreferrer"><code>browser.windows.Window</code></a> object, not a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window" rel="nofollow noreferrer">browser window</a> object.</p>
  
  <p>I can use <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/extension/getViews" rel="nofollow noreferrer"><code>browser.extension.getViews( )</code></a> to generate a list of browser window objects (aka tabs), and checking each <code>window.location.href</code> find that indeed the URL (and thus tab) does exist (somewhere), but I can't use that window object to focus on the tab nor to get a tab ID for <code>browser.tabs.update()</code>.</p>
  
  <p>In the case of multiple browser windows, I can't even get the right browser window to raise up given that window object, because the <code>window</code> objects returned by getViews have no <code>id</code> property with which to call <code>browser.windows.update()</code>.  Similar to the tabs problem.</p>
  
  <p>Finally, I can't use <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/query" rel="nofollow noreferrer"><code>browser.tabs.query( { 'url': pageURL } )</code></a> to find the tab ID, because the <code>url</code> option must conform to <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns" rel="nofollow noreferrer">match patterns</a>, which FORBID using the <code>moz-extension://</code> scheme.</p>
  
  <p>What would be exceptionally useful was if the WebExtensions API allowed an extension to find the tabs and windows of all pages that belong to itself, regardless if those pages were opened by the add-on, manually entered, a bookmark or clicking a link.</p>
  
  <p>For example, given a pageURL conforming to <code>moz-extension://MY-OWN-WEBEXT-ID/*</code>, one could do a <code>browser.tabs.query</code> and/or a <code>browser.windows.query</code> on a url matching the above pattern, and return a WebExt tab/window object, respectively.  If such a tab/window was not opened by the WebExt API (i.e. bookmark), then generate a new object (i.e. a pseudo-create), to populate with existing data (i.e. location.href, status flags, etc) and generate new data as needed (i.e. the ID numbers), such that the returned object is usable within the context of the API.</p>
  
  <p>This would fill a gap in API coverage where certain methods (i.e. <code>getViews</code>) return dead-end browser objects which have no hooks and no connection with the WebExt API and are thus mostly useless.</p>