Plugin

ReactErrorDecoder

Replaces "Minified React Error" with the actual error.

Developers
index.ts
Download

Source

src/plugins/reactErrorDecoder/index.ts
1import { Devs } from "@utils/constants";
2import definePlugin from "@utils/types";
3import { React } from "@webpack/common";
4
5let ERROR_CODES: Record<string, string> | undefined;
6
7export default definePlugin({
8 name: "ReactErrorDecoder",
9 description: &#039;Replaces "Minified React Error" with the actual error.&#039;,
10 tags: ["Developers"],
11 authors: [Devs.Cyn, Devs.maisymoe],
12 patches: [
13 {
14 find: "React has blocked a javascript: URL as a security precaution.",
15 replacement: {
16 match: /"https:\/\/react.dev\/errors\/"\+\i;/,
17 replace: "$&const vcDecodedError=$self.decodeError(...arguments);if(vcDecodedError)return vcDecodedError;"
18 }
19 }
20 ],
21
22 async start() {
23 const CODES_URL = `https:class="ts-cmt">//raw.githubusercontent.com/facebook/react/v${React.version}/scripts/error-codes/codes.json`;
24
25 ERROR_CODES = await fetch(CODES_URL)
26 .then(res => res.json())
27 .catch(e => console.error("[ReactErrorDecoder] Failed to fetch React error codes\n", e));
28 },
29
30 stop() {
31 ERROR_CODES = undefined;
32 },
33
34 decodeError(code: number, ...args: any) {
35 let index = 0;
36 return ERROR_CODES?.[code]?.replace(/%s/g, () => {
37 const arg = args[index];
38 index++;
39 return arg;
40 });
41 }
42});
43