Share User Data Between Chrome and Chrome Canary in Puppeteer
In this article
Sharing user data between Chrome and Chrome Canary in Puppeteer allows you to maintain consistent browser sessions, cookies, extensions, and cached data across both stable and development versions of Chrome. This is particularly useful for testing features in Canary without losing login states or custom configurations from your regular Chrome profile. By configuring Puppeteer to use a shared user data directory, you can seamlessly switch between browsers while preserving session data. This guide walks you through setting up data sharing safely and effectively.
What You'll Need
- Google Chrome installed on your system
- Chrome Canary installed (available from the official Chrome website)
- Puppeteer installed in your Node.js environment (via npm install puppeteer)
- Basic knowledge of Node.js and JavaScript
- Access to your system's file paths (user data directories)
- A code editor or IDE for editing JavaScript files
Step-by-Step
- Locate your Chrome user data directory. On Windows, this is typically
C:\Users\[Username]\AppData\Local\Google\Chrome\User Data. On macOS, it’s~/Library/Application Support/Google/Chrome/. On Linux, it’s~/.config/google-chrome/. - Identify the specific profile folder you want to share. By default, this is the
Defaultfolder inside theUser Datadirectory. If you use multiple profiles, choose the correct subfolder (e.g.,Profile 1). - Launch Chrome Canary with the same user data directory. In Puppeteer, you can specify the
--user-data-dirargument to point to Chrome’s existing data folder. For example:args: ['--user-data-dir=/path/to/chrome/User Data']. - Set the
--profile-directoryargument to match the profile you’re using. If using the default profile, add:'--profile-directory=Default'. For other profiles, adjust accordingly (e.g.,Profile 1). - Create a Puppeteer script that launches Chrome Canary using the shared data. Use
puppeteer.launch()with theexecutablePathset to the Canary executable and include theargsarray with the user data and profile settings. - On Windows, the executable path is usually
C:\Users\[Username]\AppData\Local\Google\Chrome SxS\Application\chrome.exe. On macOS, it’s/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary. On Linux, it may vary but often follows a similar pattern under/opt/or/usr/bin/. - Ensure no instances of Chrome or Chrome Canary are running before launching Puppeteer. Concurrent access to the same user data directory can cause profile corruption or data loss.
- Run your Puppeteer script. It should open Chrome Canary with your Chrome profile, including saved cookies, bookmarks, and login sessions.
- Verify the data is shared by logging into a site in regular Chrome, then opening the same site in Puppeteer-launched Canary. You should remain logged in.
- To reverse the process and share data from Canary to Chrome, repeat the steps but launch regular Chrome with Canary’s user data directory (located in a parallel path, e.g.,
Chrome SxSon Windows orGoogle Chrome Canaryon macOS).
Common Mistakes
- Forgetting to close existing Chrome instances before launching Puppeteer, which can lock the user data directory and cause crashes.
- Using incorrect profile directory names, such as
defaultinstead ofDefault(case-sensitive on some systems). - Pointing to the wrong executable path for Chrome Canary, especially if the installation path differs from the default.
- Assuming user data is automatically synced—Puppeteer does not sync data; it only shares access to the same directory.
- Modifying the user data directory while Puppeteer or Chrome is running, risking database corruption in
Cookies,History, orWeb Datafiles.
Tips
- Create a backup of your user data directory before starting, especially the
Defaultfolder, to prevent data loss. - Use environment variables in your Puppeteer script to manage different paths across development machines.
- Consider using a dedicated testing profile instead of your main Chrome profile to avoid unintended changes.
- Use Puppeteer’s
userDataDirlaunch option to create temporary shared directories for automated tests. - Monitor disk usage—user data directories can grow large with cached data and should be cleaned periodically.
Troubleshooting
If Chrome Canary fails to launch with shared data, first check that no Chrome processes are running in the background. Use Task Manager (Windows), Activity Monitor (macOS), or ps (Linux) to terminate all Chrome-related processes. If the error persists, verify the --user-data-dir path is correct and accessible. Ensure the directory has proper read/write permissions. If Puppeteer throws a crbug error or crashes on startup, it may be due to incompatible profile data between Chrome versions—try launching Canary manually with the same arguments to isolate the issue. If cookies or sessions aren’t shared, confirm that the --profile-directory matches exactly. In some cases, Canary may create a new profile if the directory name is misspelled. Finally, avoid using this setup on shared or public machines due to security risks from exposed session data.
Frequently Asked Questions
Can I use this method to sync extensions?
Yes, extensions installed in the shared profile will be available in both Chrome and Chrome Canary when using the same user data directory.
Will this work if I’m signed into Chrome with a Google account?
Yes, but only the local profile data is shared. Synced data like bookmarks or passwords from your Google account will appear in both if you’re signed in, but the sharing relies on local files.
Can I run Chrome and Chrome Canary at the same time with the same profile?
No. Running both browsers simultaneously with the same user data directory can corrupt profile files. Always close one before launching the other.
Is it safe to share user data between browsers?
It’s safe for personal use if you manage processes carefully, but avoid it on shared systems. Always back up data first.
Does this work with headless mode in Puppeteer?
Yes, but some profile features like extensions may not load in headless mode. Test functionality thoroughly.
What happens if I update Chrome or Chrome Canary?
Updates usually preserve profile data, but major version changes may cause incompatibilities. Always back up before updating.