@fnet/chrome-profiles
v0.1.8
Published
## Introduction
Downloads
265
Readme
@fnet/chrome-profiles
Introduction
The @fnet/chrome-profiles
tool is designed to help users easily retrieve the names of user profiles from their Google Chrome browser. This can be particularly useful for developers or anyone who needs to manage or access different user profiles on a Chrome installation.
How It Works
This tool reads the 'Local State' file within the Google Chrome user data directory. It extracts and returns an array of profile names associated with the Chrome browser. By default, it automatically determines the correct file path based on the operating system being used, ensuring a seamless experience.
Key Features
- Automatic Path Detection: The tool automatically locates the Chrome user data directory based on the operating system (Windows, macOS, or Linux).
- Profile Retrieval: It efficiently reads the 'Local State' file and extracts the names of all the user profiles available in the Chrome installation.
- Easy Integration: With an asynchronous function, it easily integrates into other applications or workflows that require access to Chrome profile information.
Conclusion
The @fnet/chrome-profiles
tool is a straightforward utility for extracting user profile names from the Chrome browser, tailored for those who need quick access to this information without delving into Chrome's user data manually.
Developer Guide for the @fnet/chrome-profiles
Library
Overview
The @fnet/chrome-profiles
library provides a straightforward way to extract information about user profiles from the Chrome browser. Primarily, it reads the 'Local State' file of the Chrome browser to gather and return a list of user profile names along with their corresponding directory paths. This can be particularly useful for applications needing to interface directly with user-specific Chrome settings or data.
Installation
To install the @fnet/chrome-profiles
library, you can use either npm or yarn:
Using npm:
npm install @fnet/chrome-profiles
Using yarn:
yarn add @fnet/chrome-profiles
Usage
This library is designed to be simple and minimalistic. Here's how you can use it to retrieve Chrome user profiles:
import getChromeProfiles from '@fnet/chrome-profiles';
(async () => {
try {
const profiles = await getChromeProfiles({
// Optional: You can specify a custom path to Chrome's user data directory.
// chromeDataPath: '/path/to/custom/chrome/user/data'
});
console.log('Chrome User Profiles:', profiles);
} catch (error) {
console.error('Error fetching profiles:', error);
}
})();
Parameters
- chromeDataPath (optional): A string to specify the path to Chrome's user data directory. If not provided, the library defaults to the standard user data directories based on the current operating system:
- Windows:
%LOCALAPPDATA%\Google\Chrome\User Data
- macOS:
~/Library/Application Support/Google/Chrome
- Linux:
~/.config/google-chrome
- Windows:
Examples
Here’s how you might use this library for a typical use case where you want to display all Chrome user profiles:
import getChromeProfiles from '@fnet/chrome-profiles';
(async () => {
try {
const profiles = await getChromeProfiles();
profiles.forEach(profile => {
console.log(`Profile Name: ${profile.name}, Directory: ${profile.dir}`);
});
} catch (error) {
console.error('Error fetching profiles:', error);
}
})();
In this example, the code fetches the profiles and logs each profile’s name and directory to the console.
Acknowledgement
This library internally utilizes Node.js built-in modules such as fs
for file system operations and path
for handling file paths. Acknowledging the efforts of contributors and maintainers of Node.js, which provides these essential modules that enable this library to function effectively.
Input Schema
$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
chromeDataPath:
type: string
description: Optional. The path to Chrome's user data directory. If not
provided, defaults to the standard path based on the current operating
system.
mode:
type: string
description: "Optional. Operation mode: 'default' to list profiles, or 'open' to
launch a profile."
profile:
type: string
description: Optional. The profile name to launch in 'open' mode.
required: []