mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 12:17:31 +08:00
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:
parent
2e25e95ce1
commit
4a62676512
|
@ -2,6 +2,12 @@ import DEBUG from "@glimmer/env";
|
||||||
import PreloadStore from "discourse/lib/preload-store";
|
import PreloadStore from "discourse/lib/preload-store";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
import getURL from "discourse-common/lib/get-url";
|
||||||
|
|
||||||
|
const BROWSER_EXTENSION_PROTOCOLS = [
|
||||||
|
"moz-extension://",
|
||||||
|
"chrome-extension://",
|
||||||
|
"webkit-masked-url://",
|
||||||
|
];
|
||||||
|
|
||||||
export default function identifySource(error) {
|
export default function identifySource(error) {
|
||||||
if (!error || !error.stack) {
|
if (!error || !error.stack) {
|
||||||
try {
|
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) || [];
|
const themeMatches = stack.match(/\/theme-javascripts\/[\w-]+\.js/g) || [];
|
||||||
|
|
||||||
for (const match of themeMatches) {
|
for (const match of themeMatches) {
|
||||||
|
@ -72,6 +84,8 @@ export function consolePrefix(error, source) {
|
||||||
return `[THEME ${source.id} '${source.name}']`;
|
return `[THEME ${source.id} '${source.name}']`;
|
||||||
} else if (source && source.type === "plugin") {
|
} else if (source && source.type === "plugin") {
|
||||||
return `[PLUGIN ${source.name}]`;
|
return `[PLUGIN ${source.name}]`;
|
||||||
|
} else if (source && source.type === "browser-extension") {
|
||||||
|
return "[BROWSER EXTENSION]";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user