How to Remove the Facebook Mini Player with a Custom Script in AdGuard

The Facebook mini player can be distracting and persistent, especially when scrolling through your feed. Thankfully, with AdGuard, you can run a custom userscript to automatically close it. In this step-by-step guide, you’ll learn how to add your custom script to AdGuard and get rid of the Facebook mini player for good.

Automatically closing the Facebook mini player using a custom AdGuard script for a cleaner browsing experience.

✅ What You Need

🧠 Why Use a Custom Script?

Facebook doesn’t provide a built-in way to disable the mini player, and browser extensions often fall short. With a custom JavaScript userscript, you can target the specific element and simulate a click on the close button automatically. AdGuard supports custom scripts, making it a powerful tool for advanced filtering and content control.

🛠️ Step-by-Step Guide to Add the Script in AdGuard

🔹 Step 1: Open AdGuard

  • If you’re using AdGuard for Desktop, launch the app.
  • If you’re using the AdGuard Browser Extension, click on the AdGuard icon in your browser’s toolbar.

🔹 Step 2: Access the Userscripts Section

For AdGuard for Windows/macOS:

  1. Go to Settings > Extensions > Userscripts.
  2. Enable the Userscripts module if it’s not already on.

For AdGuard Browser Extension:

  1. Click the AdGuard icon in your browser.
  2. Go to Settings > Extensions > Userscripts.

🔹 Step 3: Add a New Userscript

  1. Click “Manage userscripts” or “Open userscript editor”.
  2. Click “Add new script” or “+” (depending on your interface version).

🔹 Step 4: Paste Your Script

  1. In the editor window that opens, delete any placeholder content.
  2. Paste the custom script below that closes the Facebook mini player.
// ==UserScript==
// @name         Facebook Miniplayer Auto Closer (Optimized)
// @namespace    adguard-facebook-miniplayer-closer
// @version      2.1
// @description  Automatically closes the Facebook floating video popup with minimal resource use
// @match        *://*.facebook.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';

    const MINIPLAYER_SELECTOR = 'i.x1vjfegm > div[role="button"]';

    function closeMiniplayerIfExists() {
        const closeBtn = document.querySelector(MINIPLAYER_SELECTOR);
        if (closeBtn) {
            console.log('[FB Miniplayer] Found and closing.');
            closeBtn.dispatchEvent(new MouseEvent('click', {
                bubbles: true,
                cancelable: true,
                view: window
            }));
            return true;
        }
        return false;
    }

    // Observe only changes to the part of the DOM likely to contain the miniplayer
    const observer = new MutationObserver(mutations => {
        for (const mutation of mutations) {
            if (mutation.type === 'childList' && mutation.addedNodes.length) {
                if (closeMiniplayerIfExists()) break;
            }
        }
    });

    // Try once in case it’s already on screen
    closeMiniplayerIfExists();

    // Start observing the document body
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();

🔹 Step 5: Save and Enable the Script

  • Click Save (usually a disk icon or “Save” button).
  • Ensure the script is enabled (toggle switch should be on).

🔄 Test the Script

  1. Visit Facebook and play a video.
  2. Scroll down to trigger the mini player.
  3. If the script is working, the mini player should automatically close.

🧩 Troubleshooting Tips

  • Make sure your script waits for the mini player to load before clicking the close button (use setIntervalMutationObserver, or window.onload).
  • Check the browser console (F12 > Console) for any errors.
  • Ensure AdGuard’s userscript engine is enabled and up to date.

🔐 Bonus: Keep It Private

Using AdGuard instead of third-party extensions means:

  • No unnecessary permissions.
  • No data tracking.
  • Fully local control over scripts and filters.

🏁 Conclusion

With just a few steps, you can remove the Facebook mini player using AdGuard and a simple custom script. This method is safe, efficient, and totally customizable. Say goodbye to interruptions and enjoy a cleaner Facebook experience!

Leave a Comment