fondo.js
// create a new tab when alarmed chrome.alarms.onAlarm.addListener(function(alarm) { if (alarm.name === 'myAlarm') { let tabId = 0; chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ const url = 'https://www.vk.com/feed'; chrome.tabs.create({ url }, (tab) => { tabId = tab.id!; }); }); } }); // wait till the new tab will load completely to do the stuff with DOM in the new tab from content.js chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { if (tab.url!.indexOf('https://www.vk.com/feed') != -1 && changeInfo.status == 'complete') { // setTimeout chrome.tabs.sendMessage(tabId, { from: Sender.React, message: 'GET_COOKIES' }); } });Probé este código anterior, pero no funciona. Obtengo el estado === 'completo' y envío mensajes a mi contenido.js demasiado pronto cuando DOM no está listo (content.js no puede encontrar un elemento y no hace nada cuando recibe el mensaje 'GET_COOKIES') Cuando agrego setTimeout, con, por ejemplo, 3000ms para enviar mensajes, ¡eso funciona bien! Pero no quiero hacer esto, porque algunos usuarios pueden tener una conexión inestable y necesitarán más de 3 segundos, y algunos necesitarán menos de 3 segundos con una conexión más buena. Probé 'onHistoryStateUpdated' con 'webNavigation' - pero parece que tampoco funciona
¿Cómo debo resolver esto? Por favor ayuda...