From 06dee4cefc93bc9271c820ba88efea16f648b67f Mon Sep 17 00:00:00 2001 From: Beef Date: Fri, 4 Aug 2023 02:12:52 +0100 Subject: [PATCH] [Metro] Fix for 191.3, courtesy of pylix Co-authored-by: Amsyar Rasyiq <82711525+amsyarasyiq@users.noreply.github.com> --- src/lib/metro/filters.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/metro/filters.ts b/src/lib/metro/filters.ts index ee19801a..eaa6788c 100644 --- a/src/lib/metro/filters.ts +++ b/src/lib/metro/filters.ts @@ -1,8 +1,12 @@ import { MetroModules, PropsFinder, PropsFinderAll } from "@types"; +import { instead } from "@lib/patcher"; // Metro require declare const __r: (moduleId: number) => any; +// Internal Metro error reporting logic +const originalHandler = window.ErrorUtils.getGlobalHandler(); + // Function to blacklist a module, preventing it from being searched again const blacklist = (id: number) => Object.defineProperty(window.modules, id, { value: window.modules[id], @@ -30,8 +34,12 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an const id = Number(key); const module = modules[id]?.publicModule?.exports; + // HACK: Override the function used to report fatal JavaScript errors (that crash the app) to prevent module-requiring side effects + // Credit to @pylixonly (492949202121261067) for the initial version of this fix if (!modules[id].isInitialized) try { + window.ErrorUtils.setGlobalHandler(() => {}); __r(id); + window.ErrorUtils.setGlobalHandler(originalHandler); } catch {} if (!module) { @@ -71,4 +79,4 @@ export const findByDisplayName = (displayName: string, defaultExp = true) => fin export const findByDisplayNameAll = (displayName: string, defaultExp = true) => findAll(dNameFilter(displayName, defaultExp)); export const findByTypeName = (typeName: string, defaultExp = true) => find(tNameFilter(typeName, defaultExp)); export const findByTypeNameAll = (typeName: string, defaultExp = true) => findAll(tNameFilter(typeName, defaultExp)); -export const findByStoreName = (name: string) => find(storeFilter(name)); \ No newline at end of file +export const findByStoreName = (name: string) => find(storeFilter(name));