Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: automated Google OAuth setup - login + select project, then one-click Continue
Adam Eivy474bd8b900a7
diff --git a/client/src/components/calendar/ConfigTab.jsx b/client/src/components/calendar/ConfigTab.jsxindex 7601c394b0..f6d9f1a517 100644--- a/client/src/components/calendar/ConfigTab.jsx+++ b/client/src/components/calendar/ConfigTab.jsx@@ -77,24 +77,22 @@ export default function ConfigTab({ accounts, setAccounts }) {toast.success('Google Cloud Console opened in PortOS browser');};- const handleAutoConfigNavigate = async (step) => {+ const handleAutoConfigContinue = async () => {setAutoConfigBusy(true);- await api.navigateGoogleAutoConfig(step).catch(() => null);+ setAutoConfigStep('running');+ const result = await api.runGoogleAutoConfig().catch(() => null);setAutoConfigBusy(false);- setAutoConfigStep(step === 'enable-api' ? 'api' : step === 'credentials' ? 'consent' : 'credentials');- };-- const handleAutoConfigCapture = async () => {- setAutoConfigBusy(true);- const result = await api.captureGoogleCredentials().catch(() => null);- setAutoConfigBusy(false);- if (!result || result.error) {- return toast.error(result?.error || 'Could not capture credentials');+ if (!result || result.status === 'error') {+ setAutoConfigStep('login');+ return toast.error(result?.errors?.[0] || 'Automated setup failed. Try manual setup instead.');+ }+ if (result.status === 'partial') {+ toast('Setup partially completed. Some steps may need manual attention.', { icon: '⚠️' });+ } else {+ toast.success('Google OAuth setup complete!');}- toast.success('OAuth credentials captured!');setAutoConfigStep('done');fetchGoogleAuth();- // Open auth URL if availableif (result.authUrl) {window.open(result.authUrl, '_blank');toast.success('Complete Google authorization in the opened tab');@@ -378,79 +376,49 @@ export default function ConfigTab({ accounts, setAccounts }) {className="flex items-center gap-1.5 w-full px-3 py-2 text-xs rounded bg-port-accent/10 text-port-accent hover:bg-port-accent/20 border border-port-accent/20 disabled:opacity-50">{autoConfigBusy ? <RefreshCw size={14} className="animate-spin" /> : <Monitor size={14} />}- Setup with PortOS Browser (guided)+ Setup with PortOS Browser (automated)</button>- ) : autoConfigStep !== 'done' && (+ ) : autoConfigStep === 'running' ? (+ <div className="flex items-center gap-2 p-3 bg-port-bg/80 rounded border border-port-border">+ <RefreshCw size={14} className="text-port-accent animate-spin shrink-0" />+ <div className="text-xs text-gray-400">+ Automating Google Cloud setup... enabling Calendar API, configuring OAuth consent, creating credentials.+ This may take up to a minute.+ </div>+ </div>+ ) : autoConfigStep === 'login' ? (<div className="space-y-2 p-2.5 bg-port-bg/80 rounded border border-port-border"><div className="flex items-center gap-1.5 text-xs font-medium text-port-accent">- <Wand2 size={12} />- Guided Setup via PortOS Browser+ <Monitor size={12} />+ Google Cloud Console is open in the PortOS browser</div>- <div className="space-y-1.5 text-xs">- <div className={`flex items-center gap-2 ${autoConfigStep === 'login' ? 'text-white' : 'text-gray-600'}`}>- <span className={`w-4 h-4 rounded-full flex items-center justify-center text-[10px] shrink-0 ${autoConfigStep === 'login' ? 'bg-port-accent text-white' : 'bg-gray-700 text-gray-500'}`}>1</span>- Log in to Google Cloud Console in the browser window- </div>- <div className={`flex items-center gap-2 ${autoConfigStep === 'project' ? 'text-white' : 'text-gray-600'}`}>- <span className={`w-4 h-4 rounded-full flex items-center justify-center text-[10px] shrink-0 ${autoConfigStep === 'project' ? 'bg-port-accent text-white' : 'bg-gray-700 text-gray-500'}`}>2</span>- Create a project (or select existing)- </div>- <div className={`flex items-center gap-2 ${autoConfigStep === 'api' ? 'text-white' : 'text-gray-600'}`}>- <span className={`w-4 h-4 rounded-full flex items-center justify-center text-[10px] shrink-0 ${autoConfigStep === 'api' ? 'bg-port-accent text-white' : 'bg-gray-700 text-gray-500'}`}>3</span>- Enable the Google Calendar API- </div>- <div className={`flex items-center gap-2 ${autoConfigStep === 'consent' ? 'text-white' : 'text-gray-600'}`}>- <span className={`w-4 h-4 rounded-full flex items-center justify-center text-[10px] shrink-0 ${autoConfigStep === 'consent' ? 'bg-port-accent text-white' : 'bg-gray-700 text-gray-500'}`}>4</span>- Configure OAuth consent screen (External, add yourself as test user)- </div>- <div className={`flex items-center gap-2 ${autoConfigStep === 'credentials' ? 'text-white' : 'text-gray-600'}`}>- <span className={`w-4 h-4 rounded-full flex items-center justify-center text-[10px] shrink-0 ${autoConfigStep === 'credentials' ? 'bg-port-accent text-white' : 'bg-gray-700 text-gray-500'}`}>5</span>- Create OAuth client ID (Web app) with redirect URI:- </div>- <code className="block px-2 py-1 bg-port-bg rounded text-gray-400 select-all text-[10px] ml-6">- http://localhost:5555/api/calendar/google/oauth/callback- </code>+ <div className="text-xs text-gray-400 space-y-1">+ <p>1. Log in to your Google account (if not already logged in)</p>+ <p>2. Select or create a Google Cloud project</p>+ <p>Then click Continue — PortOS will automate the rest (enable API, configure OAuth, create credentials).</p></div>-- <div className="flex flex-wrap gap-1.5 pt-1">+ <div className="flex gap-2 pt-1"><button- onClick={() => { setAutoConfigStep('project'); handleAutoConfigNavigate('enable-api'); }}+ onClick={handleAutoConfigContinue}disabled={autoConfigBusy}- className="px-2 py-1 text-[10px] rounded bg-gray-700 text-gray-300 hover:bg-gray-600 disabled:opacity-50"+ className="flex items-center gap-1 px-3 py-1.5 text-xs rounded bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50">- Open Calendar API+ <Wand2 size={12} /> Continue</button><button- onClick={() => handleAutoConfigNavigate('credentials')}- disabled={autoConfigBusy}- className="px-2 py-1 text-[10px] rounded bg-gray-700 text-gray-300 hover:bg-gray-600 disabled:opacity-50"+ onClick={() => setAutoConfigStep(null)}+ className="px-3 py-1.5 text-xs rounded bg-port-border text-gray-400 hover:text-white">- Open Credentials- </button>- <button- onClick={() => handleAutoConfigNavigate('create-client')}- disabled={autoConfigBusy}- className="px-2 py-1 text-[10px] rounded bg-gray-700 text-gray-300 hover:bg-gray-600 disabled:opacity-50"- >- Create OAuth Client- </button>- <button- onClick={handleAutoConfigCapture}- disabled={autoConfigBusy}- className="flex items-center gap-1 px-2 py-1 text-[10px] rounded bg-port-success/20 text-port-success hover:bg-port-success/30 disabled:opacity-50"- >- {autoConfigBusy ? <RefreshCw size={10} className="animate-spin" /> : <Wand2 size={10} />}- Capture Credentials+ Cancel</button></div>- <button- onClick={() => setAutoConfigStep(null)}- className="text-[10px] text-gray-600 hover:text-gray-400"- >- Cancel guided setup- </button></div>- )}+ ) : autoConfigStep === 'done' ? (+ <div className="flex items-center gap-1.5 text-xs text-port-success p-2">+ <Key size={12} />+ Setup complete — credentials captured. Authorize below if prompted.+ </div>+ ) : null}{/* Manual setup (always available as fallback) */}<details className="text-xs text-gray-600">diff --git a/client/src/services/api.js b/client/src/services/api.jsindex 474d03084b..21074a3752 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -1744,6 +1744,7 @@ export const apiDiscoverCalendars = (accountId) => request(`/calendar/sync/${accexport const startGoogleAutoConfig = () => request('/calendar/google/auto-configure/start', { method: 'POST' });export const navigateGoogleAutoConfig = (step) => request('/calendar/google/auto-configure/navigate', { method: 'POST', body: JSON.stringify({ step }) });export const captureGoogleCredentials = () => request('/calendar/google/auto-configure/capture', { method: 'POST' });+export const runGoogleAutoConfig = () => request('/calendar/google/auto-configure/run', { method: 'POST' });export const getDailyReview = (date) => request(`/calendar/review/${date}`);export const confirmDailyReviewEvent = (date, data) => request(`/calendar/review/${date}/confirm`, { method: 'POST', body: JSON.stringify(data) });export const getDailyReviewHistory = (params = {}) => {diff --git a/server/routes/calendar.js b/server/routes/calendar.jsindex 96554af005..23cbcc9c6e 100644--- a/server/routes/calendar.js+++ b/server/routes/calendar.js@@ -281,6 +281,13 @@ router.post('/google/auto-configure/capture', asyncHandler(async (req, res) => {res.json(result);}));+router.post('/google/auto-configure/run', asyncHandler(async (req, res) => {+ const io = req.app.get('io');+ const result = await googleOAuthAutoConfig.runAutomatedSetup(io);+ if (result.status === 'error') return res.status(500).json(result);+ res.json(result);+}));+// === Google API Sync Routes ===router.post('/sync/:accountId/api', asyncHandler(async (req, res) => {if (!z.string().uuid().safeParse(req.params.accountId).success) {diff --git a/server/services/googleOAuthAutoConfig.js b/server/services/googleOAuthAutoConfig.jsindex a02b3caa86..23abe0f361 100644--- a/server/services/googleOAuthAutoConfig.js+++ b/server/services/googleOAuthAutoConfig.js@@ -1,139 +1,380 @@/*** Google OAuth Auto-Configure via CDP Browser- * Opens Google Cloud Console in the managed browser and guides/captures OAuth credentials.+ *+ * Flow:+ * 1. User clicks "Setup with Browser" → opens Google Cloud Console+ * 2. User logs in and selects/creates a project manually+ * 3. User clicks "Continue" → automated script handles:+ * - Enable Google Calendar API+ * - Configure OAuth consent screen+ * - Create OAuth credentials with redirect URI+ * - Extract client ID + secret+ * - Save to PortOS*/import { findOrOpenPage, evaluateOnPage, getPages } from './messagePlaywrightSync.js';import { saveCredentials, getAuthUrl } from './googleAuth.js';+import { navigateToUrl } from './browserService.js';const GCP_CONSOLE_URL = 'https://console.cloud.google.com';-const GCP_CREDENTIALS_URL = 'https://console.cloud.google.com/apis/credentials';-const GCP_ENABLE_API_URL = 'https://console.cloud.google.com/apis/library/calendar-json.googleapis.com';+const REDIRECT_URI = 'http://localhost:5555/api/calendar/google/oauth/callback';++function sleep(ms) {+ return new Promise(resolve => setTimeout(resolve, ms));+}++async function getGcpPage() {+ const pages = await getPages();+ return pages.find(p => p.url?.includes('console.cloud.google.com'));+}++async function waitForPageReady(maxWait = 15000) {+ const start = Date.now();+ while (Date.now() - start < maxWait) {+ const page = await getGcpPage();+ if (page) {+ const ready = await evaluateOnPage(page, `document.readyState === 'complete'`);+ if (ready) return page;+ }+ await sleep(1000);+ }+ return null;+}++async function navigateAndWait(url, waitMs = 3000) {+ await navigateToUrl(url);+ await sleep(waitMs);+ return waitForPageReady();+}++async function clickButtonByText(page, textPatterns, maxWait = 10000) {+ const patterns = Array.isArray(textPatterns) ? textPatterns : [textPatterns];+ const start = Date.now();+ while (Date.now() - start < maxWait) {+ const clicked = await evaluateOnPage(page, `+ (function() {+ const patterns = ${JSON.stringify(patterns)};+ // Check buttons, a tags, and elements with role=button+ const candidates = [...document.querySelectorAll('button, a, [role="button"], [role="menuitem"]')];+ for (const pattern of patterns) {+ const lp = pattern.toLowerCase();+ const match = candidates.find(el => {+ const text = (el.textContent || '').trim().toLowerCase();+ const aria = (el.getAttribute('aria-label') || '').toLowerCase();+ return text === lp || text.includes(lp) || aria.includes(lp);+ });+ if (match && !match.disabled) {+ match.click();+ return pattern;+ }+ }+ return null;+ })()+ `);+ if (clicked) return clicked;+ await sleep(1500);+ }+ return null;+}++async function fillInput(page, selector, value) {+ return evaluateOnPage(page, `+ (function() {+ const input = document.querySelector('${selector}');+ if (!input) return false;+ input.focus();+ input.value = '';+ const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;+ nativeInputValueSetter.call(input, '${value}');+ input.dispatchEvent(new Event('input', { bubbles: true }));+ input.dispatchEvent(new Event('change', { bubbles: true }));+ return true;+ })()+ `);+}++// === Public API ===export async function startAutoConfig(io) {console.log('📅 Starting Google OAuth auto-configuration via CDP browser');io?.emit('calendar:google:autoconfig', { step: 'launching', message: 'Opening Google Cloud Console...' });- // Open Google Cloud Consoleconst page = await findOrOpenPage(GCP_CONSOLE_URL);if (!page) {return { error: 'Failed to open browser. Ensure portos-browser is running.', status: 503 };}- io?.emit('calendar:google:autoconfig', { step: 'opened', message: 'Google Cloud Console opened. Please log in if needed.' });+ io?.emit('calendar:google:autoconfig', { step: 'login', message: 'Google Cloud Console opened. Log in and select a project, then click Continue.' });console.log('📅 Google Cloud Console opened in CDP browser');return {status: 'started',- message: 'Google Cloud Console opened. Follow the steps in the UI to create OAuth credentials.',- pageId: page.id+ message: 'Google Cloud Console opened. Log in and select your project, then click Continue.'};}-export async function navigateToStep(step, io) {- const urls = {- 'enable-api': GCP_ENABLE_API_URL,- 'credentials': GCP_CREDENTIALS_URL,- 'create-client': `${GCP_CREDENTIALS_URL}/oauthclient`+export async function runAutomatedSetup(io) {+ console.log('📅 Running automated Google OAuth setup via CDP');+ const errors = [];++ const emit = (step, message) => {+ io?.emit('calendar:google:autoconfig', { step, message });+ console.log(`📅 Auto-config: ${message}`);};- const url = urls[step];- if (!url) return { error: `Unknown step: ${step}`, status: 400 };+ // Verify GCP Console is open and user is logged in+ let page = await getGcpPage();+ if (!page) return { error: 'Google Cloud Console not open. Click "Setup with Browser" first.', status: 400 };++ // Step 1: Enable Google Calendar API+ emit('enable-api', 'Enabling Google Calendar API...');+ page = await navigateAndWait('https://console.cloud.google.com/apis/library/calendar-json.googleapis.com', 4000);+ if (!page) { errors.push('Failed to load Calendar API page'); }+ else {+ // Check if already enabled+ const alreadyEnabled = await evaluateOnPage(page, `+ (function() {+ const text = document.body.innerText;+ return text.includes('API enabled') || text.includes('MANAGE') || text.includes('Manage');+ })()+ `);++ if (!alreadyEnabled) {+ const clicked = await clickButtonByText(page, ['Enable', 'ENABLE']);+ if (clicked) {+ emit('enable-api', 'Calendar API enable clicked, waiting...');+ await sleep(5000);+ } else {+ errors.push('Could not find Enable button for Calendar API');+ }+ } else {+ emit('enable-api', 'Calendar API already enabled');+ }+ }++ // Step 2: Configure OAuth Consent Screen+ emit('consent', 'Configuring OAuth consent screen...');+ page = await navigateAndWait('https://console.cloud.google.com/apis/credentials/consent', 4000);+ if (!page) { errors.push('Failed to load consent screen page'); }+ else {+ // Check if consent screen is already configured+ const consentState = await evaluateOnPage(page, `+ (function() {+ const text = document.body.innerText;+ if (text.includes('Edit App') || text.includes('EDIT APP')) return 'configured';+ if (text.includes('External') || text.includes('Internal')) return 'needs-setup';+ return 'unknown';+ })()+ `);++ if (consentState === 'needs-setup') {+ // Select External and click Create+ await evaluateOnPage(page, `+ (function() {+ // Find and click External radio+ const labels = [...document.querySelectorAll('label, [role="radio"], mat-radio-button')];+ const external = labels.find(l => (l.textContent || '').toLowerCase().includes('external'));+ if (external) external.click();+ })()+ `);+ await sleep(1000);+ await clickButtonByText(page, ['Create', 'CREATE']);+ await sleep(3000);+ page = await waitForPageReady();++ if (page) {+ // Fill in app name+ await evaluateOnPage(page, `+ (function() {+ const inputs = document.querySelectorAll('input[type="text"]');+ for (const input of inputs) {+ const label = input.closest('[class*="form"]')?.querySelector('label')?.textContent || '';+ if (label.toLowerCase().includes('app name') || label.toLowerCase().includes('application name')) {+ input.focus();+ const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;+ setter.call(input, 'PortOS');+ input.dispatchEvent(new Event('input', { bubbles: true }));+ input.dispatchEvent(new Event('change', { bubbles: true }));+ return true;+ }+ }+ // Fallback: fill the first empty text input+ const first = [...inputs].find(i => !i.value);+ if (first) {+ first.focus();+ const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;+ setter.call(first, 'PortOS');+ first.dispatchEvent(new Event('input', { bubbles: true }));+ first.dispatchEvent(new Event('change', { bubbles: true }));+ return true;+ }+ return false;+ })()+ `);+ await sleep(500);++ // Click Save and Continue through each page (up to 4 times)+ for (let i = 0; i < 4; i++) {+ await sleep(2000);+ const saved = await clickButtonByText(page, ['Save and Continue', 'SAVE AND CONTINUE', 'Save and continue'], 5000);+ if (!saved) {+ // Try just Continue or Back to Dashboard+ const alt = await clickButtonByText(page, ['Continue', 'CONTINUE', 'Back to Dashboard', 'BACK TO DASHBOARD'], 3000);+ if (!alt) break;+ }+ await sleep(2000);+ page = await waitForPageReady();+ if (!page) break;+ }+ }+ emit('consent', 'OAuth consent screen configured');+ } else if (consentState === 'configured') {+ emit('consent', 'OAuth consent screen already configured');+ } else {+ emit('consent', 'Could not determine consent screen state, continuing...');+ }+ }++ // Step 3: Create OAuth Client+ emit('credentials', 'Creating OAuth credentials...');+ page = await navigateAndWait('https://console.cloud.google.com/apis/credentials', 4000);+ if (!page) { errors.push('Failed to load credentials page'); }+ else {+ // Click "+ Create Credentials" then "OAuth client ID"+ const createClicked = await clickButtonByText(page, ['Create credentials', 'CREATE CREDENTIALS', '+ Create Credentials']);+ if (createClicked) {+ await sleep(2000);+ // Click "OAuth client ID" from dropdown menu+ const oauthClicked = await clickButtonByText(page, ['OAuth client ID', 'OAuth Client ID']);+ if (oauthClicked) {+ await sleep(3000);+ page = await waitForPageReady();+ }+ }++ if (!page) {+ // Fallback: navigate directly to create page+ page = await navigateAndWait('https://console.cloud.google.com/apis/credentials/oauthclient', 4000);+ }++ if (page) {+ // Select "Web application" type+ await sleep(2000);+ await evaluateOnPage(page, `+ (function() {+ // Look for application type dropdown/select and choose "Web application"+ const selects = document.querySelectorAll('select, [role="listbox"], mat-select');+ for (const sel of selects) {+ sel.click();+ }+ // Also try clicking any dropdown that mentions "Application type"+ const dropdowns = [...document.querySelectorAll('[aria-label*="pplication type"], [class*="select"], [class*="dropdown"]')];+ for (const d of dropdowns) d.click();+ })()+ `);+ await sleep(1500);+ await clickButtonByText(page, ['Web application', 'Web Application']);+ await sleep(2000);+ page = await waitForPageReady();++ if (page) {+ // Add redirect URI+ emit('credentials', 'Adding redirect URI...');- io?.emit('calendar:google:autoconfig', { step, message: `Navigating to ${step}...` });- const page = await findOrOpenPage(url);- if (!page) return { error: 'Browser not available', status: 503 };+ // Click "Add URI" button in the redirect URIs section+ await clickButtonByText(page, ['Add URI', 'ADD URI', '+ Add URI']);+ await sleep(1000);- console.log(`📅 Auto-config navigated to ${step}`);- return { status: 'navigated', step, pageId: page.id };+ // Fill in the redirect URI+ await evaluateOnPage(page, `+ (function() {+ const redirectUri = '${REDIRECT_URI}';+ // Find input fields - look for the one near "Authorized redirect URIs"+ const inputs = [...document.querySelectorAll('input[type="text"], input[type="url"]')];+ // Find empty inputs (the newly added one)+ const emptyInput = inputs.reverse().find(i => !i.value);+ if (emptyInput) {+ emptyInput.focus();+ const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;+ setter.call(emptyInput, redirectUri);+ emptyInput.dispatchEvent(new Event('input', { bubbles: true }));+ emptyInput.dispatchEvent(new Event('change', { bubbles: true }));+ return true;+ }+ return false;+ })()+ `);+ await sleep(1000);++ // Click Create+ emit('credentials', 'Creating OAuth client...');+ await clickButtonByText(page, ['Create', 'CREATE']);+ await sleep(5000);+ page = await waitForPageReady();+ }+ }+ }++ // Step 4: Capture credentials from the creation dialog+ emit('capturing', 'Capturing OAuth credentials...');+ await sleep(2000);+ const captureResult = await captureCredentials(io);++ if (captureResult.error) {+ errors.push(captureResult.error);+ return {+ status: errors.length > 0 ? 'partial' : 'error',+ errors,+ message: 'Automated setup completed with issues. You may need to manually complete some steps.'+ };+ }++ emit('done', 'Google OAuth setup complete!');+ return {+ status: 'success',+ clientId: captureResult.clientId,+ authUrl: captureResult.authUrl,+ errors: errors.length > 0 ? errors : undefined+ };}export async function captureCredentials(io) {- console.log('📅 Attempting to capture OAuth credentials from browser');- io?.emit('calendar:google:autoconfig', { step: 'capturing', message: 'Scanning for credentials...' });+ const page = await getGcpPage();+ if (!page) return { error: 'Google Cloud Console not open in browser', status: 404 };- // Find the Google Cloud Console page- const pages = await getPages();- const gcpPage = pages.find(p => p.url?.includes('console.cloud.google.com'));- if (!gcpPage) {- return { error: 'Google Cloud Console not open in browser', status: 404 };- }+ io?.emit('calendar:google:autoconfig', { step: 'capturing', message: 'Scanning for credentials...' });- // Try to extract credentials from the OAuth client creation dialog- // Google shows a modal with Client ID and Client Secret after creating- const credentials = await evaluateOnPage(gcpPage, `+ const credentials = await evaluateOnPage(page, `(function() {- // Strategy 1: Look for the "OAuth client created" dialog- // The dialog contains two copyable text fields with client ID and secretconst allText = document.body.innerText;-- // Look for client ID pattern (ends with .apps.googleusercontent.com)const clientIdMatch = allText.match(/([0-9]+-[a-zA-Z0-9_]+\\.apps\\.googleusercontent\\.com)/);-- // Look for client secret pattern (GOCSPX- prefix)const secretMatch = allText.match(/(GOCSPX-[a-zA-Z0-9_-]+)/);+ if (clientIdMatch && secretMatch) return { clientId: clientIdMatch[1], clientSecret: secretMatch[1] };- if (clientIdMatch && secretMatch) {- return { clientId: clientIdMatch[1], clientSecret: secretMatch[1] };- }-- // Strategy 2: Look in input/textarea fields that might contain the valuesconst inputs = document.querySelectorAll('input[readonly], input[type="text"], textarea');- let clientId = null;- let clientSecret = null;-+ let clientId = null, clientSecret = null;for (const input of inputs) {const val = input.value || input.textContent || '';if (val.includes('.apps.googleusercontent.com')) clientId = val.trim();if (val.startsWith('GOCSPX-')) clientSecret = val.trim();}+ if (clientId && clientSecret) return { clientId, clientSecret };- if (clientId && clientSecret) {- return { clientId, clientSecret };- }-- // Strategy 3: Look in any element with aria-label or data attributes- const elements = document.querySelectorAll('[aria-label*="client"], [aria-label*="secret"], [data-value]');- for (const el of elements) {- const val = el.getAttribute('data-value') || el.textContent || '';- if (val.includes('.apps.googleusercontent.com')) clientId = val.trim();- if (val.startsWith('GOCSPX-')) clientSecret = val.trim();- }-- if (clientId && clientSecret) {- return { clientId, clientSecret };- }-- // Return what we found (partial or null)return clientId ? { clientId, clientSecret: null, partial: true } : null;})()`);if (!credentials) {- return {- error: 'Could not find credentials on the page. Make sure the OAuth client creation dialog is visible.',- status: 404- };+ return { error: 'Could not find credentials on the page. The OAuth creation dialog may not be visible.', status: 404 };}- if (credentials.partial || !credentials.clientSecret) {- return {- error: 'Found Client ID but not Client Secret. The secret is only shown once after creation. You may need to create a new OAuth client.',- clientId: credentials.clientId,- status: 404- };+ if (!credentials.clientSecret) {+ return { error: 'Found Client ID but not secret. You may need to create a new OAuth client.', clientId: credentials.clientId, status: 404 };}- // Save the credentialsawait saveCredentials(credentials);io?.emit('calendar:google:autoconfig', { step: 'captured', message: 'Credentials captured and saved!' });- console.log('📅 OAuth credentials captured from browser and saved');+ console.log('📅 OAuth credentials captured and saved');- // Generate the auth URL for the next stepconst authResult = await getAuthUrl();-- return {- status: 'captured',- clientId: credentials.clientId,- authUrl: authResult.url || null- };+ return { status: 'captured', clientId: credentials.clientId, authUrl: authResult.url || null };}