Hi. I have made an chrome extension and building extensions is really cool.
While I am debugging messaging between contents.js and background.js in my extension, I found this not working
//background.js
chrome.runtime.onMessage.addListener((msg) => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.storage.local.get(['msg'], function(res){
////// on this line, tabs returns empty array [] but it should returns array with tabs ////////
console.log(tabs);
})
})
)}
And I fixed by just changing two lines
//background.js
chrome.runtime.onMessage.addListener((msg) => {
////// just switched lines this
chrome.storage.local.get(['msg'], function(res){
////// and this
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
////// this returns array with tabs onject successfully ////////
console.log(tabs);
})
})
)}
I thought `chrome.storage.local.get`'s callback function should takes tabs argument from `chrome.tabs.query` but it isn't. Why this not working? Any comments will be thankful.