In my chrome extension, in my background.js file, the following code seems to trigger an error in my console.log on the launch of chrome.
“Error in event handler: Typeerror: Cannot read properties of undefined (reading ‘url’)”
The code in question is the following:
chrome.tabs.onHighlighted.addListener(function(tabId, changeInfo, tab) {
let url = tab.url;
The error doesn’t occur AFTER I have loaded other tabs, only on the initial load of chrome. I think this indicates my background script is running before the URL is available in the very first loaded tab.
I have attempted using if(tab.url) but the error still flags.
Is there a way to ignore the code if the url is undefined or another easy way to fix?