Notifications from browser extension implementation

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Implementing Notifications from a Browser Extension

Browser extensions can display system notifications through the chrome.notifications API. These are native OS notifications, not page popups — they appear in the system tray even when the browser is minimized.

Permission in Manifest

{
  "permissions": ["notifications"]
}

Notification Types

basic — title + text + icon. The most common type.

image — with a large image. Not displayed on macOS (ignored).

list — a list of items. Support depends on the OS.

progress — progress bar. Useful for background downloads.

Creating a Notification

// background/sw.js
async function showNotification(id, options) {
  return new Promise((resolve) => {
    chrome.notifications.create(id, {
      type: 'basic',
      iconUrl: chrome.runtime.getURL('icons/icon-128.png'),
      title: options.title,
      message: options.message,
      priority: 1, // 0 = low, 1 = normal, 2 = high
      requireInteraction: options.persistent ?? false, // don't hide automatically
      buttons: options.buttons ?? [],
      silent: options.silent ?? false
    }, resolve);
  });
}

// Usage
await showNotification('sync-complete', {
  title: 'Synchronization Complete',
  message: 'Added 3 new entries',
  buttons: [{ title: 'Open' }]
});

If you pass an empty string as id, the browser will generate a unique id and return it via callback.

Notification with Progress

async function showProgress(jobId, title, progress) {
  const exists = await notificationExists(jobId);

  if (!exists) {
    chrome.notifications.create(jobId, {
      type: 'progress',
      iconUrl: chrome.runtime.getURL('icons/icon-128.png'),
      title,
      message: `${progress}%`,
      progress
    });
  } else {
    chrome.notifications.update(jobId, {
      progress,
      message: `${progress}%`
    });
  }
}

function notificationExists(id) {
  return new Promise((resolve) => {
    chrome.notifications.getAll((all) => resolve(id in all));
  });
}

// Example usage for file downloads
async function downloadWithProgress(url, filename) {
  const jobId = `download-${Date.now()}`;
  await showProgress(jobId, `Downloading: ${filename}`, 0);

  const response = await fetch(url);
  const total = parseInt(response.headers.get('content-length') ?? '0');
  const reader = response.body.getReader();
  let received = 0;
  const chunks = [];

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    chunks.push(value);
    received += value.length;
    if (total > 0) {
      await showProgress(jobId, `Downloading: ${filename}`, Math.round(received / total * 100));
    }
  }

  chrome.notifications.clear(jobId);
  return new Blob(chunks);
}

Handling Notification Clicks

chrome.notifications.onClicked.addListener(async (notificationId) => {
  chrome.notifications.clear(notificationId);

  // Open the required tab or focus on existing one
  if (notificationId.startsWith('new-message-')) {
    const messageId = notificationId.split('-').at(-1);
    await openOrFocusTab(`/messages/${messageId}`);
  }
});

chrome.notifications.onButtonClicked.addListener(async (notificationId, buttonIndex) => {
  chrome.notifications.clear(notificationId);

  if (notificationId === 'sync-complete' && buttonIndex === 0) {
    // "Open" button
    await chrome.tabs.create({ url: chrome.runtime.getURL('pages/dashboard.html') });
  }
});

async function openOrFocusTab(path) {
  const url = chrome.runtime.getURL(`pages/app.html${path}`);
  const [existing] = await chrome.tabs.query({ url: `${chrome.runtime.getURL('pages/app.html')}*` });

  if (existing) {
    await chrome.tabs.update(existing.id, { active: true, url });
    await chrome.windows.update(existing.windowId, { focused: true });
  } else {
    await chrome.tabs.create({ url });
  }
}

Notifications for Periodic Tasks

A typical pattern — notifications from alarm:

chrome.alarms.onAlarm.addListener(async (alarm) => {
  if (alarm.name !== 'check-updates') return;

  const updates = await fetchUpdates();
  if (updates.length === 0) return;

  if (updates.length === 1) {
    chrome.notifications.create('update-1', {
      type: 'basic',
      iconUrl: chrome.runtime.getURL('icons/icon-128.png'),
      title: updates[0].title,
      message: updates[0].body,
      contextMessage: new URL(updates[0].url).hostname
    });
  } else {
    chrome.notifications.create('updates-batch', {
      type: 'list',
      iconUrl: chrome.runtime.getURL('icons/icon-128.png'),
      title: `${updates.length} new updates`,
      message: '',
      items: updates.slice(0, 8).map(u => ({
        title: u.title,
        message: new URL(u.url).hostname
      }))
    });
  }
});

On Windows, notifications go to the Action Center. On macOS, to the Notification Center. On Linux, through libnotify, appearance depends on the DE. Keep this in mind when testing: on macOS, the list and image types don't display additional content.