shimo164 / re-name-favbar

A Chrome extension to shorten AWS service names in the console
MIT License
3 stars 0 forks source link

fix:unchecked runtime error with no id. error handling of tab closed … #2

Closed shimo164 closed 1 year ago

shimo164 commented 1 year ago

…before the code run

i see 2 errors

Unchecked runtime.lastError: No tab with id: 995512188.

Error handling response: TypeError: Cannot read properties of undefined (reading 'url') at init (chrome-extension://clhfnpldgcplknefcglcoogolilbeedk/background.js:3:73) at chrome-extension://clhfnpldgcplknefcglcoogolilbeedk/background.js:14:7 ChatGPT The first error you are encountering, "Unchecked runtime.lastError: No tab with id: 995512188," typically arises when you're trying to interact with a tab (in this case, to inject a script) that no longer exists. This can occur if the tab was closed or navigated to a different page between the time you got its ID and the time you tried to interact with it. It can also occur if your extension's background page gets unloaded, causing the tab's ID to change.

To solve this, you could use the tab.status to check if the tab is completely loaded before calling your init function. Also, you should include a check for the existence of the tab before calling the init function to avoid trying to interact with a tab that may no longer exist.

The second error, "TypeError: Cannot read properties of undefined (reading 'url') at init," is because the tab parameter passed into the init function is undefined. This could be due to the fact that the tab was closed before your code could run.