-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(devtools): catch invalidated extension error #55697
base: main
Are you sure you want to change the base?
fix(devtools): catch invalidated extension error #55697
Conversation
…from spamming console When a browser extension is updated it becomes invalidated on currently open pages. If that extension then tries to send a message to those pages through `chrome.runtime.sendMessage(..)` then an error is thrown in the console For Angular DevTools, this results in spamming the console with "Uncaught Error: Extension context invalidated." errors. This commit catches that error and removes the event listener that triggers the `chrome.runtime.sendMessage(...)` call.
chrome.runtime.sendMessage(event.data); | ||
} catch (e) { | ||
const {message} = e as Error; | ||
if (message === 'Extension context invalidated.') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: message.includes('Extension context invalidated')
would be a little less brittle to changes in the browser.
Am I correct in assuming there's no error code or other stable identifier we could use to recognize such errors? Is error message the only option we have here?
@@ -8,11 +8,21 @@ | |||
|
|||
/// <reference types="chrome"/> | |||
|
|||
window.addEventListener('message', (event: MessageEvent) => { | |||
const eventListener = (event: MessageEvent) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: A more descriptive name would be helpful here. Maybe sendMessageToBackgroundScript
, proxyMessage
, propagateMessage
, or just onMessage
if we can't come up with anything better.
When a browser extension is updated it becomes invalidated on currently open pages. If that extension then tries to send a message to those pages through
chrome.runtime.sendMessage(..)
then an error is thrown in the console.For Angular DevTools, this results in spamming the console with "Uncaught Error: Extension context invalidated." errors.
This commit catches that error and removes the event listener that triggers the
chrome.runtime.sendMessage(...)
call.