# Debug Token Extraction

## Current Status ✅
- Content script loads successfully
- Token detection is running
- Page change detection works
- Network interception should be active

## Issue: No Tokens Found

The extension is running but not finding authentication tokens. Let's debug this step by step.

## Step 1: Verify You're Logged Into Filevine

1. Make sure you're actually logged into Filevine
2. Check that you can see projects/documents in the Filevine UI
3. If not logged in, log in first

## Step 2: Check Console for Network Interception

In the Filevine page console, you should see:
```
[Filevine Plugin] Network interception active
```

If you don't see this, the interception script didn't inject properly.

## Step 3: Manually Check for Tokens

Run these commands in the Filevine page console (DevTools → Console):

```javascript
// Check localStorage for tokens
console.log('=== Checking localStorage ===');
const keys = Object.keys(localStorage);
keys.forEach(key => {
  if (key.toLowerCase().includes('token') || key.toLowerCase().includes('auth') || key.toLowerCase().includes('fv')) {
    console.log(`Key: ${key}`, localStorage.getItem(key));
  }
});

// Check sessionStorage
console.log('=== Checking sessionStorage ===');
const sessionKeys = Object.keys(sessionStorage);
sessionKeys.forEach(key => {
  if (key.toLowerCase().includes('token') || key.toLowerCase().includes('auth') || key.toLowerCase().includes('fv')) {
    console.log(`Key: ${key}`, sessionStorage.getItem(key));
  }
});

// Check for OIDC patterns
console.log('=== Checking OIDC patterns ===');
keys.forEach(key => {
  if (key.includes('oidc')) {
    console.log(`OIDC Key: ${key}`, localStorage.getItem(key));
  }
});
```

## Step 4: Check Network Tab for Token Requests

1. Open DevTools → Network tab
2. Filter by "token" or "identity"
3. Look for requests to `identity.filevine.com` or `connect/token`
4. Check if any return `access_token` in the response

## Step 5: Test Token Extraction Manually

If you find a token in storage, test if the extractor can find it:

```javascript
// In Filevine page console
// First, let's see what the extractor is trying
console.log('Testing token extraction...');

// Check if network interception is working
// Look for this message when you refresh the page or navigate
```

## Step 6: Force Token Refresh

Sometimes tokens are only available during login/refresh:

1. Log out of Filevine
2. Log back in
3. Watch the console for: `[Filevine Plugin] Intercepted token from network`
4. This should happen during the login flow

## Common Issues

### Issue: Network Interception Not Working
**Symptom**: Don't see "Network interception active" message

**Solution**: 
- The script injection might be blocked
- Check if there are CSP (Content Security Policy) errors in console
- Try refreshing the Filevine page

### Issue: Tokens Exist But Not Found
**Symptom**: Tokens visible in storage but extension doesn't find them

**Possible Causes**:
- Token key name doesn't match our patterns
- Token is in a different storage location
- Token format is different than expected

**Solution**: 
- Run the manual check commands above
- Note the exact key names
- We may need to add those keys to the extraction patterns

### Issue: Page Already Loaded
**Symptom**: Extension loads after page is fully loaded, misses initial token

**Solution**: 
- Refresh the Filevine page after extension loads
- Or navigate to a new Filevine page
- The extension will re-check tokens on page changes

## Next Steps

1. Run the manual token checks above
2. Share what you find (key names, token format)
3. Check if network interception message appears
4. Try logging out and back in to trigger token refresh

## What to Report Back

Please share:
1. Do you see "Network interception active" in console?
2. What token-related keys did you find in localStorage/sessionStorage?
3. Are you currently logged into Filevine?
4. Any errors in the console?
