diff --git a/src/lib/metro/filters.ts b/src/lib/metro/filters.ts index ee19801..eaa6788 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));