How Apple Intelligence Writing Tools Work in Safari

This article explains the technical mechanics of how Apple Intelligence Writing Tools operate within Safari’s <textarea> and contenteditable elements. By leveraging deep integration between the WebKit rendering engine and Apple's operating system text services, Safari captures user text, processes it through language models to proofread, rewrite, or summarize, and seamlessly injects the updated content back into the webpage's Document Object Model (DOM) without breaking the web application's state.

WebKit and OS-Level Integration

Safari relies on the WebKit engine, which acts as a bridge between standard web technologies and native Apple frameworks (AppKit on macOS and UIKit on iOS and iPadOS). When a user focuses on a standard <textarea> or an HTML element with the contenteditable attribute, WebKit registers that specific DOM node as an active text input client with the operating system. This native bridge automatically exposes the Writing Tools interface—accessible via the context menu, inline icon, or selection callout—without requiring web developers to implement custom APIs.

Text Extraction and Context Mapping

When a user triggers a command to proofread, rewrite, or summarize, WebKit extracts the target text from the webpage:

  • Selection Handling: If the user highlights a specific passage, WebKit captures only that selection range. If no text is selected, WebKit automatically expands the target range to capture the entire contents of the active field.
  • Plain Text (<textarea>): Because text areas only support raw strings, WebKit extracts the plain text value directly.
  • Rich Text (contenteditable): Since contenteditable fields contain complex HTML structures, WebKit flattens the text for the language model while maintaining an internal map of the underlying DOM nodes. This allows Safari to remember where inline styles (like bolding, italics, or links) and structural breaks are located.

Processing: Proofread, Rewrite, and Summarize

Once extracted, WebKit hands the text payload to the Apple Intelligence system daemon, which processes the request using on-device foundation models or Private Cloud Compute:

  • Proofread: The model analyzes grammar, spelling, and sentence structure. It returns a list of specific character ranges and replacement suggestions. WebKit then renders native, non-DOM underline markers directly over the webpage's text, allowing the user to review and click through changes individually without altering the actual HTML until a change is accepted.
  • Rewrite: The model generates a completely new string of text adjusted for the user's selected tone (Friendly, Professional, or Concise) or a custom prompt.
  • Summarize: The model condenses the extracted text into a cohesive paragraph, key bullet points, a table, or a list.

DOM Injection and Event Firing

Inserting AI-generated text back into a modern webpage is complex because frameworks like React, Angular, and Vue rely on specific browser events to track state. If Safari simply overwrote the HTML, the webpage's internal state would desynchronize, causing the new text to disappear or corrupt when the user starts typing again.

To prevent this, WebKit simulates standard user input when applying Writing Tools changes:

  1. The beforeinput Event: Before changing the text, WebKit dispatches a cancelable beforeinput DOM event (typically using the insertReplacementText input type). This warns the web application's JavaScript that a text replacement is imminent, allowing rich-text editors to prepare their internal state.
  2. DOM Mutation: WebKit replaces the target range with the new text. In a <textarea>, it updates the plain text string. In a contenteditable field, WebKit reconciles the new text with the existing DOM tree to preserve surrounding styles. If the user utilized the Summarize tool to create bullet points or tables, WebKit automatically converts the model's output into semantic HTML tags, such as <ul>, <li>, and <table>, and injects them into the editable field.
  3. The input and change Events: Immediately after mutating the DOM, WebKit fires the standard input event. This tricks the webpage into treating the AI-generated replacement just like a standard user paste or autocomplete action, ensuring full compatibility with custom undo/redo stacks and state managers.

Developer Controls

While Writing Tools work automatically by default, WebKit provides developers with control over this behavior via the HTML writingsuggestions attribute. If a developer sets writingsuggestions="false" on a <textarea> or contenteditable element, WebKit instructs the operating system to disable the inline Apple Intelligence UI for that specific field, preventing conflicts with custom, web-based AI tools or specialized code editors.