← back to Google Places Key Provisioner
01-create-session.js
51 lines
#!/usr/bin/env node
/**
* Step 1 of provisioning Google Places API key via Browserbase.
*
* Creates a keepAlive=true session, navigates to console.cloud.google.com,
* prints the live debug URL for Steve to log into Google.
* Saves session id + connectUrl to ./session.json so step 2+ can resume.
*
* Run: node 01-create-session.js
*/
const Browserbase = require('@browserbasehq/sdk').default;
const { chromium } = require('playwright-core');
const fs = require('fs');
const path = require('path');
require('dotenv').config({ path: require('os').homedir() + '/.claude/skills/browserbase/.env' });
(async () => {
const bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY });
// keepAlive=true so the session survives between scripts; user logs in once,
// we drive the next steps without making them re-auth.
const session = await bb.sessions.create({
projectId: process.env.BROWSERBASE_PROJECT_ID,
keepAlive: true,
proxies: false,
});
console.log('session.id =', session.id);
console.log('session.connectUrl =', session.connectUrl);
console.log('session.signingUrl =', session.signingUrl);
// The live debug URL — give this to Steve so he can watch & log in
const live = `https://www.browserbase.com/devtools-fullscreen/inspector.html?wss=connect.browserbase.com/debug/${session.id}/devtools/browser/`;
console.log('LIVE_DEBUG_URL =', live);
// Persist for step 2
fs.writeFileSync(
path.join(__dirname, 'session.json'),
JSON.stringify({ id: session.id, connectUrl: session.connectUrl, debugUrl: live, createdAt: new Date().toISOString() }, null, 2)
);
// Navigate to Google Cloud Console (Steve will be prompted to log in)
const browser = await chromium.connectOverCDP(session.connectUrl);
const ctx = browser.contexts()[0];
const page = ctx.pages()[0] || await ctx.newPage();
await page.goto('https://console.cloud.google.com/projectcreate', { waitUntil: 'domcontentloaded', timeout: 45000 });
console.log('navigated to:', page.url());
await browser.close();
console.log('\n→ Hand the LIVE_DEBUG_URL to Steve. He logs in. Then run 02-create-project.js');
})();