That's probably because you are calling the function from a separate DevTools window instead of a DevTools panel.
DevTools windows don't have a tab object (actually they do but this tab object doesn't have an ID), so chrome.tabs.query() doesn't retrieve those tabs (however, chrome.windows.getAll() does return them)
In general, your code must allow for the case of an empty array being returned when calling chrome.tabs.query()
For example:
let [tab] = await chrome.tabs.query(queryOptions);
if(tab){
console.log( new URL(tab.url).hostname );
}else{
console.log("No tab found");