Chrome tabs and Google Workspace for Education

140 views
Skip to first unread message

Darin Clausing

unread,
Mar 4, 2024, 1:28:42 PM3/4/24
to Chromium Extensions
Hi everyone,

I wrote a chrome extension that basically checks for "about:blank" tabs and tabs with "unblocked" in the title. The reason is there are many unblocked games sites that bypass our filters and also sites that imbed content in about:blank which our filters can't block. The extension works fine when I install it locally (manually) but it seems to be inactive if I force install it via the Google Admin Console. I am wondering if something is wrong with my code that would make it glitch when deployed. Here is the code I am using and I would appreciate any and all assistance.

Here is my manifest.json file code:
{
  "manifest_version": 3,
  "name": "SUSD Tabs Be Gone!",
  "version": "3.0",
  "description": "Automatically closes tabs named 'about:blank' or with the URL 'about:blank' and closes tabs with unblocked in the title.",
  "permissions": ["tabs"],
  "background": {
    "service_worker": "background.js"
  }
}

And here is the background.js

// Function to close tabs with about:blank URL or title or containing "unblocked games"
function closeTabs() {
  chrome.tabs.query({}, function(tabs) {
    // Loop through all tabs
    tabs.forEach(function(tab) {
      // Check if the tab's URL is "about:blank" or if its title is "about:blank" or contains "unblocked"
      if (tab.url === "about:blank" || tab.title === "about:blank" || tab.title.toLowerCase().includes("unblocked")) {
        // Close the tab
        chrome.tabs.remove(tab.id);
      }
    });
  });
}

// Function to reload the extension
function reloadExtension() {
  chrome.runtime.reload();
}

// Event listener for when the extension is installed
chrome.runtime.onInstalled.addListener(function() {
  // Close existing tabs on installation
  closeTabs();

  // Schedule closeTabs() to run every 30 Seconds (30000 milliseconds)
  setInterval(closeTabs, 30000);

  // Schedule reloadExtension() to run every 30 Seconds (30000 milliseconds)
  setInterval(reloadExtension, 30000);

  // Event listener for tab updates
  chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    // Check if the tab's URL is "about:blank" or if its title is "about:blank" or contains "unblocked games"
    if (tab.url === "about:blank" || tab.title === "about:blank" || tab.title.toLowerCase().includes("unblocked games")) {
      // Close the tab
      chrome.tabs.remove(tabId);
    }
  });
});


Thank you,
Darin

Jackie Han

unread,
Mar 4, 2024, 2:18:38 PM3/4/24
to Darin Clausing, Chromium Extensions
You should put "chrome.tabs.onUpdated.addListener" at the top level, rather than put it in the callback of "chrome.runtime.onInstalled.addListener".

I also suggest removing the code of "setInterval()" and "reloadExtension()".


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/8883831e-ca4c-41bd-9b48-1c64b954a7a7n%40chromium.org.

Darin Clausing

unread,
Mar 4, 2024, 2:49:34 PM3/4/24
to Chromium Extensions, Jackie Han, Chromium Extensions, Darin Clausing
Thank you Jackie,

I will make the suggested changes and submit to review to see if it works with being deployed via the Google Admin console. (I made the changes and it works as a stand alone install)

Darin

Reply all
Reply to author
Forward
0 new messages