Builds the pipeline the autobuyer needs: see the page, find an element, click it. extension/ — MV3 Chromium extension. Polls /api/autobuyer/status and, while on, scrapes the target tab's HTML and posts it back. Also serves locate requests: focuses the window, scrolls the element into view, and reports its position. host_permissions is scoped to tradeify plus localhost so it cannot read other sites — an empty target pattern would otherwise capture whatever tab happened to be active, including banking or mail. app/api/autobuyer/ — status toggle, capture store, and the locate request queue. CORS is open because the extension's origin changes every time an unpacked extension is reloaded. app/autobuyer/page.tsx — ON switch, source view (default) and a rendered view. The render uses sandbox="allow-scripts" without allow-same-origin: the page's own JS is needed because sites ship content at opacity:0 and fade it in, but the frame must not reach the dashboard's same-origin API routes, which serve firm credentials. clicker/ — Python CLI. Asks the extension where a selector is, adds the element rect to the window's screen position and the browser chrome height to get desktop coordinates, then clicks with a human motion model (curved path, eased velocity, occasional overshoot, dwell before press). Raises the browser application first, since macOS consumes a click on an unfocused window rather than delivering it. Refuses to click when the element is covered by an overlay, when the coordinates fall off-screen, or when the browser cannot be confirmed frontmost. Verified: API round-trips, capture pruning, locate claim-once semantics, motion geometry and timing, and focus activation — the last two against stubs, since pyautogui and pyobjc are not installed here. NOT verified end to end: Chrome is still running a stale build of the extension, so a locate request has never completed against a real page and no real click has been sent. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { NextRequest } from 'next/server';
|
|
import { getSetting, setSetting, countPendingLocate } from '@/lib/db';
|
|
import { corsJson, corsPreflight } from '../cors';
|
|
|
|
/** Polled by the Chromium extension every few seconds, and by the AutoBuyer page.
|
|
* `pendingLocate` rides along so the extension learns about queued clicks without
|
|
* a second request on every tick. */
|
|
export async function GET() {
|
|
return corsJson({
|
|
enabled: getSetting('autobuyer_enabled') === '1',
|
|
pendingLocate: countPendingLocate(),
|
|
});
|
|
}
|
|
|
|
/** Flipped by the ON/OFF button on the AutoBuyer page. */
|
|
export async function PATCH(req: NextRequest) {
|
|
try {
|
|
const body = await req.json() as { enabled?: unknown };
|
|
if (typeof body.enabled !== 'boolean') {
|
|
return corsJson({ error: '`enabled` must be a boolean' }, { status: 400 });
|
|
}
|
|
setSetting('autobuyer_enabled', body.enabled ? '1' : '0');
|
|
return corsJson({ enabled: body.enabled });
|
|
} catch (err: any) {
|
|
return corsJson({ error: err?.message ?? 'Failed to set status' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function OPTIONS() {
|
|
return corsPreflight();
|
|
}
|