feat: persist settings and enrich conversation context
This commit is contained in:
1 parent
a36723a325
commit
2c100d72b6
84 files changed
+2248
-644
No files matched your search
+8
-81
@@ -690,7 +690,7 @@ Generate a similar message for this image..."
|
||||
|
||||
### Purpose
|
||||
|
||||
Manages the Playwright browser session with persistent cookies/storage. Handles automated login, session verification, and 2FA/captcha detection.
|
||||
Manages the headless Playwright context used after an extension dump is imported. It accepts Reddit cookies, verifies account identity, and supplies authenticated context to the remaining browser-backed operations. It never performs login.
|
||||
|
||||
### Public Methods
|
||||
|
||||
@@ -704,8 +704,8 @@ class BrowserClient {
|
||||
/** Verify browser session is active */
|
||||
verifySession(): Promise<boolean>
|
||||
|
||||
/** Perform automated login */
|
||||
login(): Promise<void>
|
||||
/** Import Reddit cookies from a validated extension dump */
|
||||
importRedditCookies(cookies: Cookie[]): Promise<void>
|
||||
|
||||
/** Get page context for operations */
|
||||
getPage(): Promise<Page>
|
||||
@@ -715,93 +715,20 @@ class BrowserClient {
|
||||
}
|
||||
```
|
||||
|
||||
### Login Flow
|
||||
### Import Flow
|
||||
|
||||
```
|
||||
1. Navigate to Reddit login page
|
||||
2. Fill username and password
|
||||
3. Submit form
|
||||
4. Check for 2FA prompt
|
||||
└─► If present: wait for manual input (with timeout)
|
||||
5. Check for captcha
|
||||
└─► If present: log warning, wait
|
||||
6. Verify login success:
|
||||
└─► Check for user menu indicator
|
||||
└─► Check for profile avatar
|
||||
└─► Fallback: API request to /api/me
|
||||
7. Save cookies to persistent directory
|
||||
8. On failure: capture debug screenshot
|
||||
```
|
||||
The dashboard validates a combined extension dump, verifies Matrix with `whoami`, imports Reddit cookies, verifies Reddit identity, and only then marks the shared account gate authenticated.
|
||||
|
||||
### Session Persistence
|
||||
|
||||
- Cookies and storage are saved to `config.browser.userDataDir`
|
||||
- Subsequent launches restore the session automatically
|
||||
- Session expires when Reddit cookies expire (requires re-login)
|
||||
- Session expiry pauses account work until a fresh extension dump is imported
|
||||
|
||||
### Dependencies
|
||||
|
||||
- `Config` - Credentials, headless mode, user data dir
|
||||
- `Logger` - Login progress, errors
|
||||
|
||||
---
|
||||
|
||||
## MessagePage
|
||||
|
||||
**File**: `src/browser/message-page.ts`
|
||||
**Lines**: 560
|
||||
**Responsibility**: Reddit DM compose page automation
|
||||
|
||||
### Purpose
|
||||
|
||||
Automates the Reddit DM compose page: filling recipient/subject/body fields, handling shadow DOM components, submitting messages, and verifying success.
|
||||
|
||||
### Public Methods
|
||||
|
||||
```typescript
|
||||
class MessagePage {
|
||||
constructor(
|
||||
private browser: BrowserClient,
|
||||
private config: Config,
|
||||
private logger: Logger
|
||||
)
|
||||
|
||||
/** Send a DM to a recipient */
|
||||
sendDM(recipient: string, subject: string, body: string): Promise<boolean>
|
||||
|
||||
/** Check if recipient field shows an error */
|
||||
hasRecipientError(page: Page): Promise<boolean>
|
||||
}
|
||||
```
|
||||
|
||||
### Shadow DOM Handling
|
||||
|
||||
Reddit's compose form uses `faceplate-*` web components:
|
||||
|
||||
```javascript
|
||||
// Fill shadow DOM input fields
|
||||
page.evaluate(({ selector, value }) => {
|
||||
const shadowInput = document.querySelector(`${selector} input`);
|
||||
if (shadowInput) {
|
||||
shadowInput.value = value;
|
||||
shadowInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
}, { selector: 'faceplate-textarea[name="body"]', value: body });
|
||||
```
|
||||
|
||||
### Dry Run Mode
|
||||
|
||||
When `config.dryRun` is enabled:
|
||||
- All fields are filled as normal
|
||||
- Submit button is NOT clicked
|
||||
- Message is logged but not sent
|
||||
- Returns `true` (simulates success)
|
||||
|
||||
### Dependencies
|
||||
|
||||
- `BrowserClient` - Playwright page access
|
||||
- `Config` - Dry run mode
|
||||
- `Logger` - Send activity
|
||||
- `Config` - Persistent session directory
|
||||
- `Logger` - Import verification progress and errors
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user