<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wuang</title>
    <description>The latest articles on DEV Community by Wuang (@wuang_0a99112cb473b42b8fe).</description>
    <link>https://dev.to/wuang_0a99112cb473b42b8fe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4268485%2F52ee7a75-afcf-489c-8c64-e130ab201dc4.jpg</url>
      <title>DEV Community: Wuang</title>
      <link>https://dev.to/wuang_0a99112cb473b42b8fe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wuang_0a99112cb473b42b8fe"/>
    <language>en</language>
    <item>
      <title>How I built a browser extension that explains a question when you highlight or snip it (MV3 + Supabase + Gemini)</title>
      <dc:creator>Wuang</dc:creator>
      <pubDate>Fri, 27 Nov 2026 08:39:28 +0000</pubDate>
      <link>https://dev.to/wuang_0a99112cb473b42b8fe/how-i-built-a-browser-extension-that-explains-a-question-when-you-highlight-or-snip-it-mv3--ob1</link>
      <guid>https://dev.to/wuang_0a99112cb473b42b8fe/how-i-built-a-browser-extension-that-explains-a-question-when-you-highlight-or-snip-it-mv3--ob1</guid>
      <description>&lt;p&gt;I'm a solo developer from Vietnam. While reviewing practice sets, I kept copying questions into a chatbot tab and back again. So I built &lt;strong&gt;QuickStudy AI&lt;/strong&gt;: highlight a question, or press &lt;code&gt;Alt+S&lt;/code&gt; and drag a box over a PDF or image, and a short answer with a 1–2 sentence explanation appears in the corner of the same page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcn0unjv7h7tyvxzhzjqv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcn0unjv7h7tyvxzhzjqv.png" alt="QuickStudy AI showing answer B with a short explanation on a practice question" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This post covers the parts that were more interesting to build than I expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture in one paragraph
&lt;/h2&gt;

&lt;p&gt;The extension (Manifest V3) never holds an AI API key. It signs the user in with Supabase Auth, then sends the question to a &lt;strong&gt;Supabase Edge Function&lt;/strong&gt; with the user's JWT. The function checks and deducts quota in Postgres, then calls Gemini with a server-side key. Payments (VietQR via PayOS, plus PayPal) go to webhooks that activate plans.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Extension ──JWT──▶ Edge Function /solve ──RPC──▶ Postgres (quota)
                          │
                          └──server key──▶ Gemini
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  1. Snipping the screen inside a service worker
&lt;/h2&gt;

&lt;p&gt;MV3 service workers have no DOM, so there's no &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt;. Instead:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The content script draws a selection overlay and sends the rectangle plus &lt;code&gt;window.innerWidth&lt;/code&gt; and &lt;code&gt;innerHeight&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The worker calls &lt;code&gt;chrome.tabs.captureVisibleTab()&lt;/code&gt; to get a PNG of the viewport.&lt;/li&gt;
&lt;li&gt;It crops the image with &lt;code&gt;createImageBitmap&lt;/code&gt; and &lt;code&gt;OffscreenCanvas&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bitmap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;createImageBitmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dataUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;scaleX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bitmap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;viewportWidth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// handles devicePixelRatio&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;scaleY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bitmap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;viewportHeight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OffscreenCanvas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sh&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bitmap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sh&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sh&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;jpeg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;convertToBlob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'image/jpeg'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.9&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Computing the scale from the bitmap size divided by the viewport size, instead of trusting &lt;code&gt;devicePixelRatio&lt;/code&gt;, fixed off-by-a-few-pixels crops on zoomed pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. UI that pages can't break
&lt;/h2&gt;

&lt;p&gt;The answer badge lives in a &lt;strong&gt;closed shadow root&lt;/strong&gt; attached to a host element with &lt;code&gt;all: initial !important&lt;/code&gt;. That way site CSS can't restyle it, and page scripts can't reach in and read the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Quota that can't be double-spent
&lt;/h2&gt;

&lt;p&gt;Each request runs one Postgres function under &lt;code&gt;SELECT ... FOR UPDATE&lt;/code&gt;. In a single transaction it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;downgrades expired plans&lt;/li&gt;
&lt;li&gt;resets the monthly allowance&lt;/li&gt;
&lt;li&gt;checks the Pro gate&lt;/li&gt;
&lt;li&gt;deducts one turn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If every Gemini model in the fallback list fails, a &lt;code&gt;refund_user_quota&lt;/code&gt; RPC gives the turn back. Both functions are &lt;code&gt;SECURITY DEFINER&lt;/code&gt; and executable only by &lt;code&gt;service_role&lt;/code&gt;, so the anon key in the extension can't call them.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Things a security review caught before launch
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A webhook that trusted an order ID from unsigned custom data. Removed.&lt;/li&gt;
&lt;li&gt;A coupons table readable with the anon key, so anyone could list every code. Replaced it with a &lt;code&gt;check_coupon(code)&lt;/code&gt; RPC that answers one code at a time.&lt;/li&gt;
&lt;li&gt;Open redirects in payment return URLs. They are now restricted to my own origin.&lt;/li&gt;
&lt;li&gt;Plan stacking that let a cheap upgrade convert a whole year of Basic into Pro. Remaining days are now prorated.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F237azh84hd231qhfo89n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F237azh84hd231qhfo89n.png" alt="The QuickStudy AI popup: plan, remaining turns, answer mode and shortcuts" width="744" height="1440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edge Add-ons: &lt;a href="https://microsoftedge.microsoft.com/addons/detail/glakjgpealjaepidajfnijelkdgfjcci" rel="noopener noreferrer"&gt;https://microsoftedge.microsoft.com/addons/detail/glakjgpealjaepidajfnijelkdgfjcci&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Website: &lt;a href="https://quickstudyai.id.vn" rel="noopener noreferrer"&gt;https://quickstudyai.id.vn&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You get 2 free turns, and the UI is in 6 languages. I'd love feedback, especially on the snipping UX and on what the explanations should cover better.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>showdev</category>
      <category>supabase</category>
    </item>
  </channel>
</rss>
