Skip to content
Search Journal
Search journal entries and projects across Journal.
Frontend Engineeringdeep dive

Copying the Web as Markdown Without a Backend

How a Manifest V3 extension separates page extraction, conservative filtering, Markdown conversion and clipboard ownership while keeping copied content local.

A web page has more than the content we want to copy. Navigation, ads, hidden help text and framework UI all live in the same tree. The job is to find the useful content before turning it into Markdown. The formatting part is relatively simple.

The Copy 2 Markdown extension handles page, selection and link actions locally in Chrome. Turndown converts the extracted HTML to Markdown. The harder part is keeping page access, content extraction and clipboard writing separate. Page access starts with a user action, and the clipboard is written from an extension-owned document.

The action can come from the popup, context menu or shortcut. The MV3 service worker checks the URL, injects the bundled content script if it has not already been injected, and sends a typed message. The popup follows the same path. There is no second extractor in the popup.

Page and selection actions return HTML, which is then converted to Markdown. The clipboard is written by an offscreen document owned by the extension. Link copying can happen in the service worker. If I only want to copy the URL, there is no need to traverse the DOM.

action → worker → extract HTML → markdown → offscreen clipboard

The extractor works with the live page. The converter takes the HTML and a base URL. The clipboard code runs in the extension document. Keeping those jobs separate stops the content script from becoming a dumping ground.

For a page copy, the extension creates a clone of the document and tries Readability first. This works well for articles, but documentation sites and app UIs often need the fallback extractor. If Readability returns too little text, the extractor checks main, article, [role="main"] and then the cleaned body. It copies the selected content root rather than the whole page.

The filters are split into three groups:

  • Structural: scripts, styles, templates, embeds, forms and native controls.
  • Semantic: toolbars, menus, tablists and tooltips.
  • Framework: a short list of known UI patterns.

The framework filter looks for known UI patterns. It does not remove every element with a familiar class. Documentation sites often use the same component libraries for content and controls, so broad selectors would remove useful information. Keeping the filters separate makes it easier to see what each one is doing.

Readability runs on a detached clone, so it cannot see computed styles. Before parsing, the extractor compares the live page with the clone and removes elements that match the hidden-content checks. Content can be hidden with clipping, absolute positioning, a 1px box or a utility class. The extractor checks the visibility and layout pattern rather than relying on one signal.

Selection copy creates a clone of the selected ranges. If the live selection has disappeared but the action still carries the selected text, the extension inserts that text directly. If nothing is selected, it returns an error instead of writing an empty clipboard.

The extracted HTML is limited to 5 MB. Pages that produce too little content fail visibly.

Turndown is used with the GFM plugin. It handles headings, emphasis, links, images, nested lists, tasks, quotes, fenced code blocks, rules and tables. Additional rules cover strikethrough, lazy image src, language hints, fence length, table pipes and whitespace. Relative URLs are resolved against the page. Links support http:, https:, mailto: and tel:. Images support only http: and https:. Credentials in URLs are ignored. Remote images are not fetched; the Markdown keeps the image destination rather than embedding a blob.

The converter takes an HTML fragment and a base URL. It has no dependency on Chrome APIs, so HTML edge cases can be tested with unit tests. Playwright is used to test the built extension and the parts that interact with the browser.

The extension requires activeTab, scripting, clipboardWrite, contextMenus and offscreen permissions. It does not request persistent host permissions, and there is no account system, backend or analytics service. The content is copied within the browser. If the URL is restricted, the extension shows an explicit error.

Where it could go next

The extraction rules will always have to deal with pages that were not part of the original test set. I’d like to grow the fixture collection with more documentation sites and app-style pages, then use those cases to improve the fallback and filtering rules without removing useful content. The hidden-content checks are another area worth testing against more layout patterns.

I’d also like to spend more time on large pages and awkward selections. The current size limit gives the extractor a clear boundary, but testing bigger documents would help show where extraction and conversion start to get expensive. Selection copying has its own edge cases too, especially when a page changes or clears the selection while the action is being handled.

Those are useful next steps because they build on the parts that already make Copy 2 Markdown work: getting the right content, keeping the filters conservative and keeping conversion separate from the page.