sodcalculator

10 Tech How-To

Why Chrome Extension Fails to Publish to Medium & Fix

Guide 10-58678 · Updated · Step by step

If your Chrome extension fails to publish to Medium, the cause is almost always a conflict between Medium’s editor and the extension’s content script, or a permissions issue that blocks the extension from interacting with the page. The fix typically involves updating your manifest permissions, adjusting content script match patterns, or disabling conflicting extensions. Below we break down the common causes and step-by-step solutions.

Background: How Chrome Extensions Interact with Medium

Chrome extensions work by injecting JavaScript (content scripts) into web pages you visit. Medium’s editor is a complex single-page application (SPA) that dynamically loads content and heavily relies on its own scripts. When your extension tries to automate publishing—for example, by filling in the title or clicking the “Publish” button—it must correctly identify the right DOM elements at the right time. Medium frequently updates its interface, so selectors that worked yesterday may break today. Additionally, Medium’s strict Content Security Policy (CSP) can block inline scripts or external requests from extensions, causing the extension to fail silently.

Common Causes of Publishing Failures

  • Outdated selectors: Medium changes class names and button IDs without notice. Your extension may be looking for an element that no longer exists.
  • Content script timing: The extension runs before Medium’s editor is fully loaded, so the publish button isn’t there yet.
  • Missing permissions: Your manifest may not include the https://medium.com/* permission, or you may be missing the storage permission needed to save your draft.
  • Conflicting extensions: Other extensions (ad blockers, grammar checkers) can alter the DOM or block your script.
  • Medium’s CSP: Medium may block certain requests your extension makes to its API or to external services.

How to Diagnose the Problem

  1. Open Chrome’s developer tools (F12) and go to the “Console” tab while on Medium’s editor page. Look for red errors related to your extension’s content script.
  2. Check the “Sources” tab to see if your content script is actually injected. If you don’t see it, your manifest match pattern is wrong.
  3. Disable all other extensions and try again. If it works, re-enable them one by one to find the culprit.
  4. Use the “Network” tab to see if any API calls from your extension are being blocked (status 403 or 404).

Step-by-Step Fixes

1. Update Manifest Permissions

Open your manifest.json and ensure the permissions include:

"permissions": ["storage", "activeTab"],
"host_permissions": ["https://medium.com/*"],
"content_scripts": [{
  "matches": ["https://medium.com/*"],
  "js": ["content.js"],
  "run_at": "document_idle"
}]

If you need to access Medium’s API directly, you may also need "https://api.medium.com/*" in host_permissions. Note that activeTab alone is not enough for persistent access to Medium.

2. Fix Content Script Timing

Change run_at to document_idle (or document_end if you need the DOM ready). Also, use a MutationObserver to wait for the publish button to appear:

const observer = new MutationObserver(() => {
  const publishBtn = document.querySelector('button[data-testid="publish-button"]');
  if (publishBtn) { /* do your thing */ }
});
observer.observe(document.body, { childList: true, subtree: true });

3. Use More Robust Selectors

Medium’s class names are hashed and change often. Prefer using data-testid attributes or ARIA labels, which are more stable. For example, the publish button often has data-testid="publish-button". If that fails, try matching by text content:

[...document.querySelectorAll('button')].find(b => b.textContent.includes('Publish'));

4. Handle Medium’s CSP

Medium’s Content Security Policy may block inline scripts or external connections. If your extension makes an external API call, ensure you declare the external domain in your manifest’s content_security_policy (if you are using a custom page) or use fetch from the background script instead of the content script. For MV3, you can use host_permissions to allow those requests.

5. Test in Incognito Mode

Sometimes extensions fail because they are not enabled in incognito. Go to chrome://extensions, find your extension, click “Details”, and enable “Allow in Incognito”. This is a common oversight when testing in a private window.

Comparison: Manifest V2 vs V3

If you are still using Manifest V2, note that Chrome is phasing it out. MV3 changes how background scripts work (service workers instead of persistent pages) and requires you to use host_permissions explicitly. Many extensions break when migrating because they rely on chrome.tabs.executeScript which is now deprecated. If your extension uses that, switch to chrome.scripting.executeScript and add the scripting permission.

Prevention: Best Practices for Medium Extensions

  • Always use data-testid or ARIA attributes over CSS classes.
  • Add a fallback that waits for the element using a MutationObserver or a retry loop.
  • Keep your extension’s permissions minimal to avoid conflicts with Medium’s CSP.
  • Test immediately after Medium updates (they often change selectors).
  • Log errors to the console with meaningful messages so you can debug quickly.

Frequently Asked Questions

Why does my extension work on other sites but not Medium?

Medium is a single-page app with a strict CSP and dynamic DOM. It also uses shadow DOM in some parts, which standard content scripts cannot access. You may need to use chrome.scripting with allFrames: true or inject into the main world instead of the isolated world.

Can I use the Medium API instead of automating the editor?

Yes, Medium has an official API that allows you to create posts programmatically. This is more reliable than UI automation because it doesn’t depend on DOM selectors. You need an integration token, which you can get from your Medium settings. The API is straightforward: POST to https://api.medium.com/v1/users/me/posts with your content.

Why does the publish button click but nothing happens?

This usually means the click event is being intercepted by Medium’s own JavaScript, or the button is disabled until required fields (like title) are filled. Make sure you set the title and content before clicking, and try dispatching a full MouseEvent with bubbles: true instead of a simple .click().

My extension works in Chrome but not in Edge or Brave—why?

Edge and Brave are Chromium-based, so most extensions work the same. However, they may have different default settings for tracking prevention or shields (Brave) that block certain requests. Also, they may not support all Chrome APIs identically. Test in those browsers and adjust permissions or use feature detection.

How do I debug if the console shows no errors?

If there are no errors, your content script may not be running at all. Check the “Sources” tab to see if your script is listed. If not, the match pattern is wrong or the extension is disabled on that page. Also, check if Medium is served over a different domain (e.g., medium.com vs towardsdatascience.com)—you may need to add those to your matches.

Is there a way to avoid this entirely?

The most robust method is to use Medium’s official API for publishing, and only use the UI for authentication. That way you bypass the editor entirely. If you must automate the UI, keep your selectors minimal and use MutationObservers to wait for elements.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →