← Back to Pull requests

Handle basic authorization flow #2

Merged
ailinykh merged 7 files (253 lines) on Nov 07, 2026 19:00 UTC
View on GitHub
ailinykh ailinykh commented on Nov 07, 2026 18:33 UTC
Author

<!-- pr-agent-generated -->

PR Type


Enhancement

___

Description


  • Add credential-based ProgressMe login handling.
  • Extract personal material identifiers, images, and titles.
  • Add randomized browser interactions and window resizing.
  • Load credentials from environment using dotenv.
  • ___

    <details> <summary><h3> File Walkthrough</h3></summary>

    <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>5 files</summary><table>
    <tr>
    <td>
    <details>
    <summary><strong>browser.ts</strong><dd><code>Add window resizing and relocate page lookup</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>

    src/api/browser/browser.ts

    <ul><li>Add <code>resizeBrowser</code> using CDP window bounds commands and detach the <br>session afterward.<br> <li> Move hostname-based <code>getPage</code> lookup here, retaining new-page fallback.</ul>

    </details>

    </td>
    <td><a href="https://github.com/ailinykh/progress-dump/pull/2/files#diff-a9199e52c26bc574c0f2773bfd6e97cf5f9a2e7eb45a0efc42d1a07017959ce7">+36/-1</a>&nbsp; &nbsp; </td>

    </tr>

    <tr>
    <td>
    <details>
    <summary><strong>index.ts</strong><dd><code>Expose browser sizing and interaction helper functions</code>&nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>

    src/api/browser/index.ts

    <ul><li>Export <code>resizeBrowser</code>, <code>safeClick</code>, and <code>safeType</code>.<br> <li> Update <code>getPage</code> import to its new location in <code>browser.ts</code>.</ul>

    </details>

    </td>
    <td><a href="https://github.com/ailinykh/progress-dump/pull/2/files#diff-803f93335eb621b8cfe68d622dfa3d9dfd811ce2ce41945f66df61ea931008b4">+9/-3</a>&nbsp; &nbsp; &nbsp; </td>

    </tr>

    <tr>
    <td>
    <details>
    <summary><strong>page.ts</strong><dd><code>Add randomized mouse and keyboard interaction helpers</code>&nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>

    src/api/browser/page.ts

    <ul><li>Replace page lookup with <code>safeClick</code> and <code>safeType</code> interaction helpers.<br> <li> Randomize click coordinates, mouse movement, and interaction delays.<br> <li> Clear existing input using platform-specific shortcuts before typing <br>characters individually.</ul>

    </details>

    </td>
    <td><a href="https://github.com/ailinykh/progress-dump/pull/2/files#diff-db7d77c1b6f12d7e61d44b4029d7b70c428ab3c83e8ddae0c6563b3ed05e33de">+65/-15</a>&nbsp; </td>

    </tr>

    <tr>
    <td>
    <details>
    <summary><strong>index.ts</strong><dd><code>Implement conditional ProgressMe login and readiness checks</code></dd></summary>
    <hr>

    src/api/progressme/index.ts

    <ul><li>Add <code>handleLogin</code> with credential validation and target navigation.<br> <li> Detect the login button and conditionally submit credentials using <br>browser helpers.<br> <li> Coordinate clicking with navigation, revisit the target, and verify <br>the avatar after login.<br> <li> Wait for the requested content selector before returning.</ul>

    </details>

    </td>
    <td><a href="https://github.com/ailinykh/progress-dump/pull/2/files#diff-f3736055e83a0eab8577a8bd95cac0849b7d3f559594dd58bdf4a9778c522a95">+54/-0</a>&nbsp; &nbsp; </td>

    </tr>

    <tr>
    <td>
    <details>
    <summary><strong>index.ts</strong><dd><code>Integrate authentication and extract personal material metadata</code></dd></summary>
    <hr>

    src/index.ts

    <ul><li>Load environment configuration and pass <code>USER_EMAIL</code> and <code>USER_PASSWORD</code> <br>to <code>handleLogin</code>.<br> <li> Replace viewport sizing with browser window resizing through CDP.<br> <li> Extract and log material IDs, image URLs, and titles from personal <br>material cards.<br> <li> Note scroll-based pagination as future work.</ul>

    </details>

    </td>
    <td><a href="https://github.com/ailinykh/progress-dump/pull/2/files#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80">+34/-13</a>&nbsp; </td>

    </tr>
    </table></details></td></tr><tr><td><strong>Dependencies</strong></td><td><details><summary>2 files</summary><table>
    <tr>
    <td>
    <details>
    <summary><strong>package.json</strong><dd><code>Add dotenv dependency for environment configuration loading</code></dd></summary>
    <hr>

    package.json

  • Add dotenv at ^18.0.9 for environment configuration loading.
  • </details>

    </td>
    <td><a href="https://github.com/ailinykh/progress-dump/pull/2/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519">+1/-0</a>&nbsp; &nbsp; &nbsp; </td>

    </tr>

    <tr>
    <td>
    <details>
    <summary><strong>package-lock.json</strong><dd><code>Update dependency lockfile alongside dotenv dependency addition</code></dd></summary>
    <hr>

    package-lock.json

    <ul><li>Lockfile changed alongside the dependency update; its diff was <br>omitted.</ul>

    </details>

    </td>
    <td><a href=""></a></td>

    </tr>
    </table></details></td></tr></tr></tbody></table>

    </details>

    ___

    Diff: 253 lines (+221 / -32) across 7 files Reviewer: chatgpt-codex-connector[bot] Review duration: 26m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.68) × (1 − Review Confidence (0.77)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.68 · 253 lines diff across 7 files
    0.68
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.60 · 5 substantive comment(s)
    0.60
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    76%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.331
    Sensitive Paths sensitive_paths
    0.068
    Real PR Conversation Timeline
    9 items
    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 07, 2026 18:33 UTC
    Bot

    <!-- codex-pull-request-review-summary -->
    <!-- codex-review-state:v1 {"code_review":{"commit_sha":"54c4e71b8aa5eeefa9c1bf6e7d55c9ba8aa37bfc","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->

    <details>
    <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>

    This comment shows the latest Codex review activity on this pull request.

    | Review | Status | Commit | Review trigger |
    | --- | --- | --- | --- |
    | 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-07T18:34:42.942478Z">2026-11-07T18:34:42.942478Z</relative-time> | 54c4e71 | PR opened |

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Nov 07, 2026 18:34 UTC
    Code Review
    src/api/progressme/index.ts:1
    @@ -0,0 +1,54 @@
    +import { Page } from "puppeteer";
    +import { safeClick, safeType } from "../browser";
    +
    +export async function handleLogin(
    +  page: Page,
    +  {
    +    target,
    +    selector,
    +    email,
    +    password,
    +  }: { target: string; selector: string; email: string; password: string },
    +) {
    +  if (!email || !password) throw "Credentials missing";

    <sub><sub>!P2 Badge</sub></sub> Require credentials only when login is necessary

    When the connected browser already has an authenticated session but USER_EMAIL or USER_PASSWORD is unset, this check aborts the scrape before inspecting the page. The browser setup explicitly reuses a running browser or the persistent .puppeteer profile, and the previous entry point allowed those existing sessions to work without credentials. Move this validation into the branch that actually performs login so authenticated users can continue without supplying their password again.

    Useful? React with 👍 / 👎.

    <!-- codex-code-review-finding:v1 -->

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 07, 2026 18:34 UTC
    Reviewer

    <!-- codex-review-receipt:v1 -->

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: 54c4e71b8a

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    github-actions[bot] github-actions[bot] commented on Nov 07, 2026 18:34 UTC
    Bot

    PR Reviewer Guide 🔍

    <!-- pr-agent:review:full -->

    (Review updated until commit https://github.com/ailinykh/progress-dump/commit/8f356057e8caa6b705f7093ea74cf8e22c3d9b47)

    Here are some key observations to aid the review process:

    <table>
    <tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>: 3 🔵🔵🔵⚪⚪</td></tr>
    <tr><td>🧪&nbsp;<strong>No relevant tests</strong></td></tr>
    <tr><td>🔒&nbsp;<strong>No security concerns identified</strong></td></tr>
    <tr><td>⚡&nbsp;<strong>Recommended focus areas for review</strong><br><br>

    <details><summary><a href='https://github.com/ailinykh/progress-dump/pull/2/files#diff-db7d77c1b6f12d7e61d44b4029d7b70c428ab3c83e8ddae0c6563b3ed05e33deR5-R12'><strong>Offscreen interactions</strong></a>

    waitForSelector() and boundingBox() do not scroll an element into view. If a login field or submit button is below the viewport, these coordinates fall outside the visible page, so the mouse click misses; typing can target the wrong field or login can time out. safeType() has the same problem. Scroll each element into view before measuring its bounds, or use an element interaction that scrolls automatically.
    </summary>

    const button = await page.waitForSelector(selector);
    const box = await button.boundingBox();
    
    if (!box) throw `Element ${selector} not found`;
    
    // 2. Pick a random point inside the button (not the exact center!)
    const x = box.x + Math.floor(Math.random() * box.width);
    const y = box.y + Math.floor(Math.random() * box.height);
    

    </details>

    </td></tr>
    </table>

    <!-- pr-agent-review-state:v1
    {"findings":[{"body":"Offscreen interactions\n\nwaitForSelector() and boundingBox() do not scroll an element into view. If a login field or submit button is below the viewport, these coordinates fall outside the visible page, so the mouse click misses; typing can target the wrong field or login can time out. safeType() has the same problem. Scroll each element into view before measuring its bounds, or use an element interaction that scrolls automatically.","finding_id":"39b58bca7ebe","first_seen":"2026-11-07T18:34:40.748619Z","last_seen":"2026-11-07T18:46:20.615528Z","last_seen_head_sha":"8f356057e8caa6b705f7093ea74cf8e22c3d9b47","line_end":12,"line_start":5,"path":"src/api/browser/page.ts","state":"ACTIVE"}],"last_run":{"complete":true,"excluded_files":[],"head_sha":"8f356057e8caa6b705f7093ea74cf8e22c3d9b47","kind":"full","run_id":"https://github.com/ailinykh/progress-dump/commit/8f356057e8caa6b705f7093ea74cf8e22c3d9b47"},"schema_version":1}
    -->

    github-actions[bot] github-actions[bot] commented on code on Nov 07, 2026 18:35 UTC
    Code Review
    src/api/progressme/index.ts:1
    @@ -0,0 +1,54 @@
    +import { Page } from "puppeteer";
    +import { safeClick, safeType } from "../browser";
    +
    +export async function handleLogin(
    +  page: Page,
    +  {
    +    target,
    +    selector,
    +    email,
    +    password,
    +  }: { target: string; selector: string; email: string; password: string },
    +) {
    +  if (!email || !password) throw "Credentials missing";
    +
    +  await page.goto(target, {
    +    waitUntil: "networkidle0",
    +    timeout: 30_000,
    +  });
    +
    +  const login_button = 'button[test="login_b_login"]';
    +  await page.waitForSelector(`${login_button}, ${selector}`, {
    +    visible: true,
    +    timeout: 3000,
    +  });
    +
    +  if (
    +    await page
    +      .$eval(login_button, (el) => el.checkVisibility())
    +      .catch(() => false)
    +  ) {
    +    console.info("🔑 perform authorization flow");
    +    await safeType(page, 'input[type="email"]', email);
    +    await safeType(page, 'input[type="password"]', password);
    +
    +    // combine to avoid race condition
    +    await Promise.all([
    +      page.waitForNavigation(),
    +      safeClick(page, login_button),
    +    ]);

    Suggestion: Wait for an authenticated UI state rather than requiring navigation. If login completes through an API request without changing the document or URL, waitForNavigation() times out despite successful authentication. [possible issue, importance: 6]

        await Promise.all([
          page.waitForSelector(".avatar-box", {
            visible: true,
            timeout: 30_000,
          }),
          safeClick(page, login_button),
        ]);
    

    github-actions[bot] github-actions[bot] commented on code on Nov 07, 2026 18:35 UTC
    Code Review
    src/api/browser/page.ts:1
    @@ -1,17 +1,67 @@
    -import { Browser, Page } from "puppeteer";
    -
    -export async function getPage(
    -  browser: Browser,
    -  hostname: string,
    -): Promise<Page> {
    -  const pages = await browser.pages();
    -
    -  for (const page of pages) {
    -    const url = new URL(page.url());
    -    if (url.hostname === hostname) {
    -      return page;
    -    }
    -  }
    +import { Page } from "puppeteer";
    +
    +export async function safeClick(page: Page, selector: string): Promise<void> {
    +  // 1. Locate the button and get its exact physical coordinates
    +  const button = await page.waitForSelector(selector);
    +  const box = await button.boundingBox();
    +
    +  if (!box) throw `Element ${selector} not found`;
    +
    +  // 2. Pick a random point inside the button (not the exact center!)
    +  const x = box.x + Math.floor(Math.random() * box.width);
    +  const y = box.y + Math.floor(Math.random() * box.height);
    +
    +  // 3. Move the mouse to the destination
    +  // For high-security sites, use a library like 'ghost-cursor' to handle micro-movements,
    +  // or introduce a multi-step movement manually.
    +  await page.mouse.move(x, y, { steps: 25 }); // Steps create a smoother path
    +
    +  // 4. Short human delay right before clicking
    +  await new Promise((r) => setTimeout(r, 50 + Math.random() * 100));
    +
    +  // 5. Fire a trusted hardware click
    +  await page.mouse.click(x, y, { delay: 30 + Math.random() * 50 }); // Simulates key-down hold time
    +}
    +
    +export async function safeType(
    +  page: Page,
    +  selector: string,
    +  text: string,
    +): Promise<void> {
    +  // 0. Perform random delay before any action
    +  await new Promise((r) => setTimeout(r, 500 + Math.random() * 3000));
     
    -  return await browser.newPage();
    +  // 1. Safely click to focus the input field first (using human-like click math)
    +  const input = await page.waitForSelector(selector);
    +  const box = await input.boundingBox();

    Suggestion: Wait for visibility and scroll the input into view before calculating mouse coordinates. boundingBox() can return coordinates outside the viewport, causing the click to miss and credentials to be typed into the wrong field or nowhere. [possible issue, importance: 7]

      const input = await page.waitForSelector(selector, { visible: true });
      if (!input) throw new Error(`Element ${selector} not found`);
      await input.scrollIntoView();
      const box = await input.boundingBox();
    

    ailinykh ailinykh commented on Nov 07, 2026 18:45 UTC
    Author

    /review

    Assignees
    ailinykh ailinykh
    Labels
    risk: low confidence: 76.6% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 68.1% (HIGH) · Higher = larger blast radius
    68.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 76.6% · Lower = rushed or shallow review
    76.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.0% · Safe to merge
    16.0%