Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only thing I can find in the documentation pertaining to the ID is the following Excerpt:</p> <blockquote> <p>id ( integer ) The ID of the tab. Tab IDs are unique within a browser session.</p> </blockquote> <p>So what we can glean from this is that no two tabs will ever get the same ID in the same session. There's no information in the docs about how they're generated.</p> <p>Ultimately I think any approach that is predictive in this sense is doomed to bugs &amp; failure, you should be building a responsive application vs. a predictive one.</p> <p>Instead of assuming the next tab will be opened with ID # 12, Capture the creation of the tab, then you'll know the ID and can perform operations based on that.</p> <p>What you need is the <a href="http://code.google.com/chrome/extensions/tabs.html#event-onCreated" rel="nofollow"><code>tab onCreated event</code></a>. When a tab is created you'll get a <a href="http://code.google.com/chrome/extensions/tabs.html#type-Tab" rel="nofollow"><code>tab</code> Object</a> which you can get the <code>tabid</code> and <code>windowid</code> from and perform whatever actions you desire.</p> <p>Since you didn't tell us much about your ultimate goal, I can't give you any specific examples / code to help you out other than pointing you in the right direction.</p> <hr> <p><em>Continuation from comments:</em></p> <p>If you're just looking to look up the tab by ID wouldn't it be easier to store your tab meta-data in a dictionary instead of a list?</p> <pre><code>var metadataRepository = {}; metadataRepository[tab.id] = tab.metadata; </code></pre> <p>Then:</p> <pre><code>var metadata = metadataRepository[tabId]; if (metadata) { // Do Stuff } </code></pre> <hr> <p><em>Even More Information:</em></p> <p>As of my current Chrome (19.xxx...) the V8 Engine Supports the JavaScript 1.6 method of <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter" rel="nofollow"><code>Array.filter(...)</code></a></p> <p>I did a little test <a href="http://jsfiddle.net/sw56m/" rel="nofollow">here</a> that simulates searching an array using filter and doing a type inspection &amp; string search each iteration (something common).</p> <p>It took 25ms on my machine (relatively new, i7-2600k) to blast through 10,000 entries. While this isn't fast compared to compiled languages, it's going to be sub millisecond when dealing with 100ish tabs. I dont think you need to worry about performance too much.</p> <p>IF your app is constantly looking this up, consider a local cache or the dictionary mentioned above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload