From 06a843e61eb0e5f17e6c939f9a0bfc35ae083a2c Mon Sep 17 00:00:00 2001 From: Criz Games <38948134+CrizGames@users.noreply.github.com> Date: Thu, 8 Jul 2021 00:46:06 +0200 Subject: [PATCH] Add support for other chrome profiles in reactdevtools.js (#802) * Update reactdevtools.js * Update reactdevtools.js --- injector/src/modules/reactdevtools.js | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/injector/src/modules/reactdevtools.js b/injector/src/modules/reactdevtools.js index 7e328fc8..dca6faec 100644 --- a/injector/src/modules/reactdevtools.js +++ b/injector/src/modules/reactdevtools.js @@ -6,11 +6,38 @@ export const REACT_DEVTOOLS_ID = "fmkadmapgofadopljbjfkapdkoienihi"; const findExtension = function() { let extensionPath = ""; + // Get path to user data folder if (process.platform === "win32") extensionPath = path.resolve(process.env.LOCALAPPDATA, "Google/Chrome/User Data"); else if (process.platform === "linux") extensionPath = path.resolve(process.env.HOME, ".config/google-chrome"); else if (process.platform === "darwin") extensionPath = path.resolve(process.env.HOME, "Library/Application Support/Google/Chrome"); else extensionPath = path.resolve(process.env.HOME, ".config/chromium"); - extensionPath += `/Default/Extensions/${REACT_DEVTOOLS_ID}`; + + // If default profile doesn't exist + if (!fs.existsSync(extensionPath + "/Default")) { + const profiles = fs.readdirSync(extensionPath).filter((fileName) => { + // Check if file is a profile folder + return fileName.startsWith("Profile") && !fileName.endsWith("store"); + }); + // Check for a profile with react dev tools installed + let foundExtension = false; + for (const p of profiles) { + const exPath = `${extensionPath}/${p}/Extensions/${REACT_DEVTOOLS_ID}`; + if (fs.existsSync(exPath)) { + extensionPath = exPath; + foundExtension = true; + break; + } + } + // Return empty if no installation found + if (!foundExtension) { + return ""; + } + } + else { + extensionPath += `/Default/Extensions/${REACT_DEVTOOLS_ID}`; + } + + // Get latest version if (fs.existsSync(extensionPath)) { const versions = fs.readdirSync(extensionPath); extensionPath = path.resolve(extensionPath, versions[versions.length - 1]);