executeScript
returns the last evaluated result of the code into the callback, see documentation.
Note, when running in the active tab there's no need for chrome.tabs.query
. You can simply omit the tab id (this is what "optional" means in the documentation) and the entire code will be:
chrome.tabs.executeScript({
code: 'document.getElementById("element-id").style.filter',
}, results => {
if (!chrome.runtime.lastError) {
const mainPageResult = results[0];
console.log(mainPageResult);
// do something with mainPageResult here inside the callback
}
}
It can't transfer DOM elements, Map, Set, ArrayBuffer, classes, functions, and so on - it can only transfer JSON-compatible simple objects and types. So, you'll need to manually extract the required data and pass it as a simple array or object.
The callback is invoked asynchronously so these topics might be useful: