DEV: Identify errors/deprecations triggered by browser extensions (#24820)

It's possible for browser extensions to trigger JS errors and deprecation warnings. That can lead to significant confusion and noise in our logs/metrics. One recent example we've identified is the 'Wappalyzer' extension triggering the `ember-global` deprecation.

This commit will clearly identify these errors/deprecations with a `[BROWSER EXTENSION]` prefix in the console.
This commit is contained in:
David Taylor 2023-12-11 14:22:44 +00:00 committed by GitHub
parent 2e25e95ce1
commit 4a62676512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,12 @@ import DEBUG from "@glimmer/env";
import PreloadStore from "discourse/lib/preload-store";
import getURL from "discourse-common/lib/get-url";
const BROWSER_EXTENSION_PROTOCOLS = [
"moz-extension://",
"chrome-extension://",
"webkit-masked-url://",
];
export default function identifySource(error) {
if (!error || !error.stack) {
try {
@ -22,6 +28,12 @@ export default function identifySource(error) {
""
);
if (BROWSER_EXTENSION_PROTOCOLS.any((p) => stack.includes(p))) {
return {
type: "browser-extension",
};
}
const themeMatches = stack.match(/\/theme-javascripts\/[\w-]+\.js/g) || [];
for (const match of themeMatches) {
@ -72,6 +84,8 @@ export function consolePrefix(error, source) {
return `[THEME ${source.id} '${source.name}']`;
} else if (source && source.type === "plugin") {
return `[PLUGIN ${source.name}]`;
} else if (source && source.type === "browser-extension") {
return "[BROWSER EXTENSION]";
}
return "";