Manifest v2 to v3 - Getselected

1,227 views
Skip to first unread message

Kramos

unread,
May 7, 2022, 6:29:44 AM5/7/22
to Chromium Extensions
I know the  chrome.tabs.getSelected(null, function(tab) {
window.id = tab.id;
}); Has decreapted , and my extension dont work, someone can jhelp me?
code: 

//background
chrome.runtime.sendMessage({popupOpen: true});
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('button').addEventListener('click', onclick, false);
function onclick() {
var token = document.getElementById("token").value
chrome.tabs.getSelected(null, function(tab) {
window.id = tab.id;
});
chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
chrome.tabs.sendMessage(window.id,token);
});
document.getElementById("status").innerHTML = "Conecting...";
document.getElementById("status").style = "color: orange";
chrome.runtime.sendMessage({info: "clicked"});
}
}, false);
Obrigado.

wOxxOm

unread,
May 7, 2022, 10:12:31 AM5/7/22
to Chromium Extensions, kikoram...@gmail.com
No need for getSelected, you should just use chrome.tabs.query correctly:

chrome.tabs.query({currentWindow: true, active: true}, tabs =>  chrome.tabs.sendMessage(tabs[0].id, token));

Kramos

unread,
May 7, 2022, 11:16:29 AM5/7/22
to Chromium Extensions, wOxxOm, Kramos
Getting a new error...

imagem_2022-05-07_155937031.png

code: 
popup.js:

//background
chrome.runtime.sendMessage({popupOpen: true});
document.addEventListener('DOMContentLoaded', function() {
    document.querySelector('button').addEventListener('click', onclick, false);
    function onclick() {
        var token = document.getElementById("token").value
   
        chrome.tabs.query({currentWindow: true, active: true}, tabs =>  chrome.tabs.sendMessage(tabs[0].id, token));

   
    }
}, false);



/////

wOxxOm

unread,
May 7, 2022, 11:27:32 AM5/7/22
to Chromium Extensions, kikoram...@gmail.com, wOxxOm
It means the content script doesn't run in the tab or there's no onMessage listener. If you reloaded the extension on chrome://extensions page without reload the tab(s), the content scripts won't run by themselves in Chrome, see https://stackoverflow.com/q/10994324
Reply all
Reply to author
Forward
0 new messages