<?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: Kenneth Fang</title>
    <description>The latest articles on DEV Community by Kenneth Fang (@kengomatsuo).</description>
    <link>https://dev.to/kengomatsuo</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%2F4255837%2F4a92d775-5454-4a8f-ac76-3eb5711d5d19.jpg</url>
      <title>DEV Community: Kenneth Fang</title>
      <link>https://dev.to/kengomatsuo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kengomatsuo"/>
    <language>en</language>
    <item>
      <title>Building a snippet keyboard for iPhone and a paste picker for the Mac menu bar</title>
      <dc:creator>Kenneth Fang</dc:creator>
      <pubDate>Fri, 20 Nov 2026 13:55:05 +0000</pubDate>
      <link>https://dev.to/kengomatsuo/building-a-snippet-keyboard-for-iphone-and-a-paste-picker-for-the-mac-menu-bar-4a8c</link>
      <guid>https://dev.to/kengomatsuo/building-a-snippet-keyboard-for-iphone-and-a-paste-picker-for-the-mac-menu-bar-4a8c</guid>
      <description>&lt;p&gt;I make &lt;a href="https://cutling.matsuokengo.com/" rel="noopener noreferrer"&gt;Cutling&lt;/a&gt;, an app that keeps the text you type again and again (your address, bank details, an email signature, the reply you send every week) and pastes it with one tap. On iPhone and iPad it's a keyboard you switch to in any app; on the Mac it sits in the menu bar and Shift-Command-V opens a picker at your cursor. The code is open source under GPL-3.0 (&lt;a href="https://github.com/kengomatsuo/Cutling" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;). Here's how the two halves work, and the platform corners I ran into.&lt;/p&gt;

&lt;h2&gt;
  
  
  On iPhone: a keyboard extension that inserts text
&lt;/h2&gt;

&lt;p&gt;A custom keyboard gets a &lt;code&gt;textDocumentProxy&lt;/code&gt;, and inserting a snippet is one call: &lt;code&gt;proxy.insertText(value)&lt;/code&gt;. Images are different, because a keyboard can't insert an image into a text field. Cutling puts the image on &lt;code&gt;UIPasteboard.general&lt;/code&gt; with its real type (it reads the type from the data with &lt;code&gt;CGImageSourceGetType&lt;/code&gt;, so a GIF stays a GIF) and you paste it.&lt;/p&gt;

&lt;p&gt;That pasteboard write is why the keyboard asks for Full Access (&lt;code&gt;RequestsOpenAccess&lt;/code&gt; in its Info.plist). Without it, a keyboard extension can't touch the pasteboard or the shared container at all. Cutling has no server, no analytics and no account, so Full Access here means "the keyboard can read the snippets the app saved and copy an image for you", and nothing leaves the phone unless you turn iCloud sync on.&lt;/p&gt;

&lt;p&gt;The proxy also tells the keyboard what kind of field it's in through &lt;code&gt;keyboardType&lt;/code&gt; and &lt;code&gt;textContentType&lt;/code&gt;. Cutling uses that to put the right snippets first: in an email field your email addresses come up before your signature.&lt;/p&gt;

&lt;h2&gt;
  
  
  On the Mac: a global hotkey, a picker and a synthesized ⌘V
&lt;/h2&gt;

&lt;p&gt;macOS still has no modern replacement for Carbon's &lt;code&gt;RegisterEventHotKey&lt;/code&gt;, so that's what registers Shift-Command-V system-wide (the same path the sindresorhus/KeyboardShortcuts library uses). The hotkey opens a picker at the cursor. When you choose a snippet, Cutling puts it on the pasteboard and posts a ⌘V key-down and key-up into the front app with &lt;code&gt;CGEvent&lt;/code&gt; on the HID event tap.&lt;/p&gt;

&lt;p&gt;Posting key events into another app needs Accessibility permission, and without it the &lt;code&gt;CGEvent&lt;/code&gt; posts fail silently, with no error at all. So Cutling checks &lt;code&gt;AXIsProcessTrusted()&lt;/code&gt; first, prompts if it isn't, falls back to copy-only when you say no, and has a deep link into System Settings for when the prompt was already dismissed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clipboard history without a change notification
&lt;/h2&gt;

&lt;p&gt;The Mac app also keeps a history of what you copy. macOS has no pasteboard-change notification, so Cutling polls &lt;code&gt;NSPasteboard.general.changeCount&lt;/code&gt; on a timer every 500 ms, the same approach Maccy takes, which is quick enough that you don't notice and light on CPU.&lt;/p&gt;

&lt;p&gt;The part I care about most is what it refuses to record. Password managers and other apps flag sensitive or short-lived copies with marker types, and Cutling skips any item carrying &lt;code&gt;org.nspasteboard.ConcealedType&lt;/code&gt;, &lt;code&gt;org.nspasteboard.TransientType&lt;/code&gt;, &lt;code&gt;org.nspasteboard.AutoGeneratedType&lt;/code&gt;, &lt;code&gt;com.apple.is-sensitive&lt;/code&gt; or 1Password's own type. Those names come from the conventions at nspasteboard.org, and following them is how a clipboard manager stays out of your passwords.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small things that turned out to matter
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Snippets can expire on a date you pick, which is what you want for a one-time code or a temporary address.&lt;/li&gt;
&lt;li&gt;Each snippet gets one of 12 colours and an SF Symbol, because on a keyboard you scan by colour long before you read.&lt;/li&gt;
&lt;li&gt;Deleted snippets sit in Recently Deleted for 30 days, since a keyboard is an easy place to delete the wrong thing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cutling is $4.99 once on the App Store, one purchase for Mac, iPhone and iPad. If you build keyboard extensions yourself and know a better way around the image-insert limit, I'd like to hear it in the comments.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
      <category>macos</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How a web page steals your tap in Safari, and how my extension takes it back</title>
      <dc:creator>Kenneth Fang</dc:creator>
      <pubDate>Fri, 20 Nov 2026 13:53:25 +0000</pubDate>
      <link>https://dev.to/kengomatsuo/how-a-web-page-steals-your-tap-in-safari-and-how-my-extension-takes-it-back-1h24</link>
      <guid>https://dev.to/kengomatsuo/how-a-web-page-steals-your-tap-in-safari-and-how-my-extension-takes-it-back-1h24</guid>
      <description>&lt;p&gt;I make &lt;a href="https://undirect.matsuokengo.com/" rel="noopener noreferrer"&gt;Undirect&lt;/a&gt;, a Safari extension for Mac, iPhone and iPad that stops pages from taking your click somewhere you didn't ask to go. It's open source (&lt;a href="https://github.com/kengomatsuo/undirect" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;), and most of what I learned building it came from reading the ad scripts themselves. This post is about what those scripts do and why the obvious fix doesn't work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Patching &lt;code&gt;window.open&lt;/code&gt; stops almost nothing
&lt;/h2&gt;

&lt;p&gt;The first thing everyone tries is wrapping &lt;code&gt;window.open&lt;/code&gt;. One streaming site I studied had already tried it on its own pages, and its own source comments said the ads kept firing anyway. When I pulled the 70 KB ad tag it loads (FingerprintJS bundled inside), the serving methods were named right in the code: &lt;code&gt;POP_UP&lt;/code&gt;, &lt;code&gt;POP_UNDER&lt;/code&gt;, &lt;code&gt;NEW_TAB_FOCUS&lt;/code&gt;, &lt;code&gt;NEW_TAB_REPLACE&lt;/code&gt;, &lt;code&gt;POP_IN_PAGE&lt;/code&gt;, and a back-button redirect behind a feature flag.&lt;/p&gt;

&lt;p&gt;The tag takes a click in four ways, and only one of them looks like a popup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A transparent form&lt;/strong&gt; with &lt;code&gt;target="_blank"&lt;/code&gt;, fixed at 100% by 100%, holding a submit input. Your click lands on the submit button, which opens a new tab with no JavaScript call to hook.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An overlay at z-index 2147483647&lt;/strong&gt; that reads &lt;code&gt;elementFromPoint&lt;/code&gt; to learn what is underneath, takes the press, then hides itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An anchor with &lt;code&gt;target="_blank"&lt;/code&gt;&lt;/strong&gt; that the script clicks from its own handler. &lt;code&gt;window.open&lt;/code&gt; is never called.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;about:blank&lt;/code&gt;, then a rewrite of &lt;code&gt;window.top&lt;/code&gt;'s URL.&lt;/strong&gt; This is the redirect you actually see: the page you were reading turns into a different site.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;window.location&lt;/code&gt; can't be replaced by any script, so the last one is invisible to anything running in the page. You can't wrap your way out of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Split the job: detect in the page, block at the network
&lt;/h2&gt;

&lt;p&gt;A content script can't cancel a top-level navigation that another script started. So Undirect splits the work. The JavaScript half watches for these patterns and names the host the page tried to reach. The background page turns that host into a &lt;code&gt;declarativeNetRequest&lt;/code&gt; rule, so the second attempt dies at the request and never loads.&lt;/p&gt;

&lt;p&gt;Navigations go through the background page's &lt;code&gt;onBeforeNavigate&lt;/code&gt;, judged before the commit, so a chain of server redirects answers for the address you asked for and not wherever it ended up.&lt;/p&gt;

&lt;h2&gt;
  
  
  What separates a theft from a normal trip off-site: the press
&lt;/h2&gt;

&lt;p&gt;These networks wait for a real &lt;code&gt;pointerdown&lt;/code&gt; or &lt;code&gt;keydown&lt;/code&gt; and ride it. So the rule is simple to state: a cross-site navigation right after a press you aimed somewhere else is the press being taken. A cross-site navigation with no press behind it is you typing an address, opening a bookmark or going back, and it's left alone.&lt;/p&gt;

&lt;p&gt;The content script reports every trusted press along with wherever the thing under your finger honestly leads. The order of the decision is: same site is always fine, then a rule you set, then no press means it was your own doing, then the press pointing at that destination, then the default.&lt;/p&gt;

&lt;p&gt;Two details cost me a while:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The press has to be written down synchronously.&lt;/strong&gt; Safari unloads the background page, and my first version awaited a storage restore before recording the press. On wake-up the press landed after the navigation it was meant to explain, so the theft was judged as if nobody had pressed anything. Now it lives in a plain map written without awaiting anything.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;iOS Safari leaves &lt;code&gt;openerTabId&lt;/code&gt; off pop tabs.&lt;/strong&gt; So a tab created within a second of a press in another tab is treated as that tab's doing; where the press pointed still lets a real link through.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  A window size used to mean "this is a sign-in"
&lt;/h2&gt;

&lt;p&gt;A sign-in flow opens a window at a size (&lt;code&gt;width=500,height=620&lt;/code&gt;), and a pop-under wants a full tab, so for a while a features string with a size was my signal that the page meant it. Then a site asked for &lt;code&gt;width=800,height=600&lt;/code&gt; and called &lt;code&gt;focus()&lt;/code&gt; on the window every 300 ms until it had it. Now a size counts only when the address also names a way back to the page, which Google's popup sign-in does through &lt;code&gt;redirect_uri&lt;/code&gt; and share sheets do by carrying the page's own address.&lt;/p&gt;

&lt;p&gt;The same site laid an empty &lt;code&gt;div&lt;/code&gt; over the whole page at &lt;code&gt;opacity:0.01&lt;/code&gt;, &lt;code&gt;z-index:999999&lt;/code&gt;, with an &lt;code&gt;onclick&lt;/code&gt; that opens the pop, and put it back every two seconds. A click-outside backdrop is see-through by its background and sits under its modal; an empty layer hidden by its own opacity has no reason to exist except to be pressed unseen, so Undirect removes it on sight.&lt;/p&gt;

&lt;h2&gt;
  
  
  Showing what the block stopped
&lt;/h2&gt;

&lt;p&gt;A network rule kills the request before the page sees anything, so the extension can't witness its own best outcome, and an empty popup reads exactly like nothing happened. &lt;code&gt;declarativeNetRequest.getMatchedRules()&lt;/code&gt; (Safari 15.4 and later, with the &lt;code&gt;declarativeNetRequestFeedback&lt;/code&gt; permission) says which rules matched in a tab, so every address a page tried to reach shows up in the toolbar popup, blocked or not. You can allow or block each one on that site or everywhere.&lt;/p&gt;

&lt;p&gt;The guard stays off on a site until you press its toolbar button there, there's no account or server, and there's a &lt;a href="https://undirect.matsuokengo.com/demo/" rel="noopener noreferrer"&gt;page of deliberately broken demo sites&lt;/a&gt; to try it on. It's $1.99 once on the App Store for Mac, iPhone and iPad.&lt;/p&gt;

&lt;p&gt;If you've seen a hijack it misses, the issue tracker on GitHub is the place. I read every script that gets reported.&lt;/p&gt;

</description>
      <category>safari</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>privacy</category>
    </item>
  </channel>
</rss>
