๐Ÿ“ฆ karishnu / pixel-prompt

PixelPrompt is a Chrome extension that lets you visually select any region of your running application, write a prompt describing what you want changed, and copies a rich, structured context bundle straight to your clipboard. Paste it into any AI assistant (ChatGPT, Claude, Copilot, Cursor, etc.) and get back a precise edit against the right files.

โ˜… 0 stars โ‘‚ 0 forks ๐Ÿ‘ 0 watching
๐Ÿ“ฅ Clone https://github.com/karishnu/pixel-prompt.git
HTTPS git clone https://github.com/karishnu/pixel-prompt.git
SSH git clone git@github.com:karishnu/pixel-prompt.git
CLI gh repo clone karishnu/pixel-prompt
Loading files...
๐Ÿ“„ README.md

PixelPrompt

Point at your UI. Describe the change. Let AI do the rest.

Editing frontend code with AI is powerful โ€” but describing which part of the UI you want changed is surprisingly hard. You're stuck typing things like "the card in the second row" or "the button next to the search bar" into a prompt box that has zero visual context.

PixelPrompt fixes this. It's a Chrome extension that lets you visually select any region of your running application, write a prompt describing what you want changed, and copies a rich, structured context bundle โ€” complete with the original source file paths and code โ€” straight to your clipboard. Paste it into any AI assistant (ChatGPT, Claude, Copilot, Cursor, etc.) and get back a precise edit against the right files.

How It Works

  • Click the PixelPrompt icon in your Chrome toolbar. The page dims and your cursor becomes a crosshair.
  • Click and drag to draw a selection rectangle around the part of the UI you want to change.
  • Write your prompt in the popover that appears (e.g. "Make this card's border thicker and add a hover shadow").
  • Hit Copy. PixelPrompt resolves the selected elements back to their original source files, bundles everything into a Markdown document, and copies it to your clipboard.
  • Paste into your AI tool of choice. The AI now has the exact source code, file paths, and your visual intent โ€” no guesswork.
The copied bundle includes:

  • Your prompt
  • The resolved source file paths and their full contents
  • An HTML snapshot of the selected region
  • File and line count metadata

Features

  • Visual region selector โ€” click-and-drag to select any rectangular area of the page.
  • Framework-aware source resolution โ€” automatically detects React, Vue, Svelte, and Angular components and maps DOM elements back to their source files.
  • Source map resolution โ€” parses JavaScript source maps to trace bundled/transpiled code back to original source files, even in production builds.
  • Vite dev mode support โ€” in Vite dev environments, crawls the ESM module graph to discover component-to-file mappings and fetches raw source directly from the dev server.
  • Structured Markdown output โ€” copies a clean, AI-ready Markdown bundle with file sections, language-tagged code blocks, and the HTML snapshot.
  • Multi-file context โ€” if your selection spans multiple components, PixelPrompt resolves and includes all of them (up to 10 files / 2,000 lines).
  • Works with any AI tool โ€” the output is plain Markdown on your clipboard. Paste it into ChatGPT, Claude, Cursor, GitHub Copilot Chat, or anything else.

Installation

PixelPrompt is available on the Chrome Web Store.

  • Visit the PixelPrompt listing on the Chrome Web Store.
  • Click Add to Chrome.
  • Pin the extension to your toolbar for quick access.
That's it โ€” navigate to any locally running (or deployed) web application and start selecting.

How Source Map Resolution Works

Modern frontend toolchains (Vite, webpack, esbuild, etc.) transform and bundle your source files before serving them to the browser. The code running in the DOM bears little resemblance to what you actually wrote. PixelPrompt bridges this gap using multiple resolution strategies:

1. Framework component detection (Page Bridge)

PixelPrompt injects a small bridge script into the page's main world (not the isolated content-script world) so it can access framework internals that are invisible to regular extensions:

FrameworkHow it finds the component
ReactWalks the fiber tree via __reactFiber$ to find the nearest component, reads _debugSource / __source for file info
VueReads __vueParentComponent and extracts __file / component name
SvelteLooks for __svelte context keys and constructor names
AngularInspects __ngContext__ for component constructors
This gives PixelPrompt a component name (e.g. Header) and, when available in dev mode, the exact source file path and line number.

2. Source map parsing

If the framework metadata doesn't include a file path, PixelPrompt falls back to source maps:

  • Discovers <script> tags in the DOM and fetches each script's content.
  • Extracts the //# sourceMappingURL= comment from the bottom of each script (supports both external URLs and inline data: URIs).
  • Parses the source map โ€” decodes the Base64-VLQ mappings to build a line/column โ†’ original-file lookup table entirely in the browser (no server needed).
  • Matches component names to source file lists inside the parsed maps (e.g. component Header โ†’ src/components/Header/Header.tsx).

3. Vite dev mode module crawling

Vite serves each source file as a separate ES module in development. PixelPrompt detects Vite by looking for the @vite/client script tag, then:

  • Finds the main entry module (e.g. /src/main.tsx).
  • Recursively crawls the import graph, following import statements to discover every module in the app.
  • Builds a component name โ†’ source file path map (e.g. App โ†’ src/App.tsx).
  • Fetches original, un-transformed source code directly from the Vite dev server using the ?raw query parameter.

4. Fallback strategies

When none of the above yield a result, PixelPrompt tries heuristic matching:

  • CSS Modules patterns โ€” class names like Header_wrapper__a1b2c โ†’ component Header.
  • Styled-components patterns โ€” class names like sc-Header โ†’ component Header.
  • Test ID attributes โ€” data-testid, data-cy values matched against source map file lists.
  • Direct data attributes โ€” data-source-file, data-source-map-url + data-generated-line / data-generated-column for manual annotation.
The result: no matter how your app is built, PixelPrompt does its best to hand you the original source code and file paths โ€” not transpiled bundle output.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.

Development setup

  • Clone the repository:
git clone <repository-url>
   cd ui-select-extension

  • Install dependencies:
npm install

  • Build the extension:
npm run build
This bundles everything into the dist/ directory using esbuild.

  • Load the extension in Chrome:
  • Navigate to chrome://extensions
  • Enable Developer mode (toggle in the top-right)
  • Click Load unpacked and select the dist/ folder
  • For development with type-checking:
npm run watch
Then rebuild with npm run build after making changes and reload the extension in Chrome.

Running tests

npm test

Tests use Jest with jsdom and cover the core modules (overlay, popover, select mode, source map resolver, toast, utilities).

Project structure

src/
โ”œโ”€โ”€ background/          # Service worker โ€” handles extension lifecycle and messages
โ”œโ”€โ”€ content/             # Content scripts โ€” injected into web pages
โ”‚   โ”œโ”€โ”€ select-mode.ts   # Core selection logic (drag, lock, copy)
โ”‚   โ”œโ”€โ”€ overlay.ts       # Visual backdrop and selection box
โ”‚   โ”œโ”€โ”€ popover.ts       # Prompt input popover UI
โ”‚   โ”œโ”€โ”€ toast.ts         # Copy-confirmation toast
โ”‚   โ”œโ”€โ”€ page-bridge.ts   # MAIN-world script for framework introspection
โ”‚   โ””โ”€โ”€ sourcemap-resolver.ts  # Source map parsing and component resolution
โ”œโ”€โ”€ popup/               # Extension popup (triggers select mode)
โ”œโ”€โ”€ shared/              # Shared types and utilities
โ””โ”€โ”€ manifest.json        # Chrome extension manifest (MV3)

License

This project is licensed under the MIT License. See the LICENSE file for details.