Does Chrome extension chome.tabs.onUpdate work twice?

//In background.js chrome.tabs.onUpdated.addListener(function(tabid, info, tab) { console.log(info); }); 

I am trying to configure it, so onUpdate is launched once every time a YouTube video page is uploaded. I want to wait for the download after uploading the video to YouTube. When I boot directly from the URL, I get what I expect, but when I go to the suggested video, there are 2 load / end cycles. One for the current video, one for the next video.

Direct url

This is the output for videos with a direct URL.

Navigation

This is what happens if I go to a YouTube video while watching another YouTube video.

In my manifest, I have a simple background.js script, permission for webNaviagtion and Tabs.

I do not know why it works twice.

0
source share
1 answer

tabs.onUpdated is called for each frame / iframe , the Youtube watch page loads one.

webNavigation API provides frameId for frameId listeners, on the main page there is frameId == 0 .

Please note that Youtube does not reload the page when a user navigates from one video to another or from the YouTube main page to a video page, so you can use the chrome.webNavigation.onHistoryStateUpdated event chrome.webNavigation.onHistoryStateUpdated or a script content that will listen for DOM events used to detect these changes site, namely "spfdone" .

+2
source

Source: https://habr.com/ru/post/1210126/


All Articles