Ultimately I want to use puppeteer to capture links to files stored on a google drive and paste them into a google sheet. Of course, the path to this simple objective isn’t simple.
To do this I need to be logged into google.
I am using the latest version of Chrome and the latest version of puppeteer on MacOS sonoma.
Logging in on Chrome via puppeteer is one option I have explored, but it seems anathema to the spirit of Chrome security, it is complex, requires installing extraneous stuff that complexifies and litters my environment, and I couldn’t get it work.
Opening Chrome with a specific profile (already logged in) is the next option I have tried (details below) and I can’t get it work.
My next option to explore is connecting puppeteer to an already running Chrome process. Don’t want to go there yet, because I’d really like a fully automated solution.
Key questions:
(1) What is simplest way to access google drive via puppeteer? (Simplest meaning easiest to implement and maintain and most fully automated.)
(2) Has anyone been able to automate logging in with stealth code and not complexifiying the shit out of this step to get to drive?
(3) Has anyone been able to open Chrome already logged into a profile?
Here is the simplest version of my code that won’t work.
const puppeteer = require("puppeteer");
// const puppeteer = require("puppeteer-core");
const chrome_executible = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
const user_data_dir = '/Users/jasonbronfeld/Library/Application Support/Google/Chrome/Profile 1';
(async () => {
try {
const browser = await puppeteer.launch({
headless: false,
executablePath: chrome_executible,
userDataDir: user_data_dir
});
console.log(await browser.version());
const page = await browser.newPage();
await page.goto('https://drive.google.com/drive/my-drive');
} catch(err){
console.log(err);
}
})();
It lands me here:
(https://i.sstatic.net/cWLMqn8g.png)
As you can see, not in my profile. To illustrate the attempt at process one, when I try to login manually, or automated I get: (https://i.sstatic.net/fLDN3V6t.png)
Jason Bronfeld is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1