/* globals chrome, console, alert, confirm, setTimeout, clearTimeout */ 'use strict'; function createNewTabAndWaitForReady() { chrome.tabs.create({ url: chrome.extension.getURL('manifest.json') }, function(tab) { var newTabId = tab.id; chrome.tabs.onUpdated.addListener(onUpdated); var timer = setTimeout(function checkReady() { // Assume that the extension page has already loaded. alert('Test timed out! The onUpdated event has not been triggered!'); chrome.tabs.onUpdated.removeListener(onUpdated); }, 800); function onUpdated(tabId, changeInfo, tab) { console.log(tabId, changeInfo, tab); if (tabId != newTabId || changeInfo.status != 'complete') return; clearTimeout(timer); alert('Got changeInfo.status = complete, as expected!'); chrome.tabs.onUpdated.removeListener(onUpdated); } // For completeness, log onReplaced events. They are not triggered for // extension pages though (nor should they). chrome.tabs.onReplaced.addListener(function(addedTabId, removedTabId) { if (removedTabId == newTabId) { console.log('Replaced ' + removedTabId + ' with ' + addedTabId); newTabId = addedTabId; } }); }); } if (confirm('Want to add the tabs.onUpdated event?')) chrome.tabs.onUpdated.addListener(console.info.bind(console)); chrome.browserAction.onClicked.addListener(function(tab) { createNewTabAndWaitForReady(); });