mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(devtools): catch invalidated extension error to prevent devtools from spamming console (#55697)
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. PR Close #55697
This commit is contained in:
parent
03b35270b0
commit
be82f282a4
2 changed files with 19 additions and 6 deletions
|
|
@ -90,3 +90,22 @@ if (!backendInitialized) {
|
|||
};
|
||||
retry();
|
||||
}
|
||||
|
||||
const proxyEventFromWindowToDevToolsExtension = (event: MessageEvent) => {
|
||||
if (event.source === window && event.data) {
|
||||
try {
|
||||
chrome.runtime.sendMessage(event.data);
|
||||
} catch (e) {
|
||||
const {message} = e as Error;
|
||||
if (message.includes('Extension context invalidated.')) {
|
||||
console.error(
|
||||
'Angular DevTools: Disconnecting content script due to invalid extension context. Please reload the page.',
|
||||
);
|
||||
window.removeEventListener('message', proxyEventFromWindowToDevToolsExtension);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('message', proxyEventFromWindowToDevToolsExtension);
|
||||
|
|
|
|||
|
|
@ -8,12 +8,6 @@
|
|||
|
||||
/// <reference types="chrome"/>
|
||||
|
||||
window.addEventListener('message', (event: MessageEvent) => {
|
||||
if (event.source === window && event.data) {
|
||||
chrome.runtime.sendMessage(event.data);
|
||||
}
|
||||
});
|
||||
|
||||
if (document.contentType === 'text/html') {
|
||||
const script = document.createElement('script');
|
||||
script.src = chrome.runtime.getURL('app/detect_angular_for_extension_icon_bundle.js');
|
||||
|
|
|
|||
Loading…
Reference in a new issue