I'm using a listener in the background page to know when a tab is loaded:
chrome.tabs.onUpdated.addListener(function (tabId) { })
But the listener is fired twice: when the page has started loading, and when the page has finished.Is there a way to differentiate the two cases?
To make a background tab active in Google Chrome automatically, you need to do the following. Press and hold Ctrl + Shift keys together on the keyboard, and only then click the link that you want to switch to immediately. It will be opened in a new foreground tab. This trick should work in all Chromium-based browsers.
Depending on the extensions you have installed, sometimes Google Chrome will continue to run in the background on your computer after closing it. You might notice this, especially after setting up a new computer and when you install a fresh version of the browser.
Ctrl + Shift + B Click on the word "History" in the left pane Right-click on a column header in the right pane, such as "Name" Left-click "Most Recent Visit", a check mark will then appear next to it, and you will now see that column You can drag the columns left or right, to place them as you wish Under "History" in ...
Luckily have found the solution.
There is an additional parameter that holds the status value:
chrome.tabs.onUpdated.addListener(function (tabId , info) { if (info.status === 'complete') { // your code ... } });
Status can be either loading
or complete
.
I wanted a easier way to do this after opening a tab
function createTab (url) { return new Promise(resolve => { chrome.tabs.create({url}, async tab => { chrome.tabs.onUpdated.addListener(function listener (tabId, info) { if (info.status === 'complete' && tabId === tab.id) { chrome.tabs.onUpdated.removeListener(listener); resolve(tab); } }); }); }); }
so it would be
let tab = await createTab('http://google.com');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With