Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AleksanderBodurri
Copy link
Member

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.

…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.
@AleksanderBodurri AleksanderBodurri added target: patch This PR is targeted for the next patch release area: devtools labels May 6, 2024
@ngbot ngbot bot added this to the Backlog milestone May 6, 2024
chrome.runtime.sendMessage(event.data);
} catch (e) {
const {message} = e as Error;
if (message === 'Extension context invalidated.') {
Copy link
Contributor

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) => {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: devtools target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants