Chrome extension

61 views
Skip to first unread message

Bob Bryan

unread,
Jul 7, 2025, 9:20:28 PM7/7/25
to Google Apps Script Community
I want to create a Chrome extension that will disable the Compose button in GMail. I do not want someone to create an email from that account, I do want them to be able to reply however.

Google Pony

unread,
Jul 10, 2025, 4:02:24 AM7/10/25
to Google Apps Script Community

Hi Bob,


I’d be happy to help you with your Chrome extension to disable the Gmail compose button while allowing replies. Below is a solution you can implement:


Solution Overview

You’ll need to create a simple Chrome extension that uses JavaScript to hide or disable the Gmail compose button. Here’s how to do it:


1. Create the Extension Files

Your extension will need:

A manifest.json file (required for all Chrome extensions).

A content.js file to manipulate the Gmail DOM.


2. Folder Structure

disable-gmail-compose/  
├── manifest.json  
└── content.js  


3. Code Implementation


A. manifest.json

{
  "manifest_version": 3,
  "name": "Disable Gmail Compose Button",
  "version": "1.0",
  "description": "Disables the Gmail compose button while allowing replies.",
  "content_scripts": [
    {
      "matches": ["https://mail.google.com/*"],
      "js": ["content.js"],
      "run_at": "document_end"
    }
  ],
  "permissions": ["activeTab"]
}


B. content.js

// Function to hide the compose button
function hideComposeButton() {
  const composeButton = document.querySelector('[role="button"][gh="cm"]');
  if (composeButton) {
    composeButton.style.display = 'none';
  }
}

// Run the function when the page loads and on DOM changes (Gmail is dynamic)
document.addEventListener('DOMContentLoaded', hideComposeButton);
const observer = new MutationObserver(hideComposeButton);
observer.observe(document.body, { childList: true, subtree: true });

Run the function when the page loads and on DOM changes (Gmail is dynamic)

document.addEventListener('DOMContentLoaded', hideComposeButton);

const observer = new MutationObserver(hideComposeButton);

observer.observe(document.body, { childList: true, subtree: true });


4. Load the Extension in Chrome

1. Go to chrome://extensions/.

2. Enable Developer mode (toggle in the top-right).

3. Click Load unpacked and select your extension folder.


How It Works

The extension injects content.js into Gmail.

It hides the compose button by targeting its [gh="cm"] attribute (Gmail’s internal identifier).

A MutationObserver ensures the button stays hidden even if Gmail dynamically reloads the UI.


Notes & Limitations:

This hides the button but doesn’t prevent keyboard shortcuts (e.g., `c` for compose). To block those, you’d need additional logic.

If Gmail’s DOM structure changes, the selector (`[gh="cm"]`) may need updating.


Let me know if you need further adjustments or enhancements!


Sincerely yours,
Sandeep Kumar Vollala
Consultant
LinkedIn Logo WhatsApp Logo

Bob Bryan

unread,
Jul 10, 2025, 9:27:01 AM7/10/25
to google-apps-sc...@googlegroups.com
Thank you for your response. This is a slight variation of several attempts I have made. Unfortunately, this did not work either. I am assuming it may have something to do with being in a Google Workspace environment. Profiles are managed by the administrator, of which I am one. When I create the extension, it shows that it is installed. I then start gmail and the Compose button is still visible. Any other ideas?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/f20664f1-5aff-40d0-93d5-928b1fefe827n%40googlegroups.com.


--

Bob Bryan

unread,
Jul 10, 2025, 9:33:15 AM7/10/25
to google-apps-sc...@googlegroups.com
image.png
As you can see, the button is still visible


On Thu, Jul 10, 2025 at 3:02 AM Google Pony <pony...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/f20664f1-5aff-40d0-93d5-928b1fefe827n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages