Browser extension REST API server integration

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_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • 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_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Implementing Browser Extension REST API Integration with Server

A browser extension communicates with your server via REST API: synchronizes data, saves settings, and receives configuration updates. Extension-specific concerns: strict CSP policy, isolated execution context, and Manifest V3 restrictions.

Communication Architecture

Extension (content script)
    ↓ chrome.runtime.sendMessage
Extension (background service worker)
    ↓ fetch() → REST API
Server Backend
    ↓ JSON Response
Background service worker
    ↓ chrome.runtime.sendResponse
Content script

Background Service Worker (Manifest V3)

// background.js
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.action === 'save_item') {
    saveItemToServer(message.data)
      .then(result => sendResponse({ success: true, data: result }))
      .catch(err  => sendResponse({ success: false, error: err.message }));
    return true;  // async response
  }
});

async function saveItemToServer(itemData) {
  const token = await getStoredToken();

  const resp = await fetch('https://api.example.com/v1/items', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + token,
      'X-Extension-Version': chrome.runtime.getManifest().version,
    },
    body: JSON.stringify(itemData),
  });

  if (!resp.ok) {
    if (resp.status === 401) await refreshToken();
    throw new Error(`API error: ${resp.status}`);
  }

  return resp.json();
}

CORS on Server

// Allow requests from extension
// Extension origin format: chrome-extension://EXTENSION_ID

class CorsMiddleware
{
    public function handle(Request $request, Closure $next): Response
    {
        $origin = $request->header('Origin');

        $allowedOrigins = [
            'https://app.example.com',
            'chrome-extension://' . config('services.extension.chrome_id'),
            'moz-extension://' . config('services.extension.firefox_id'),
        ];

        if (in_array($origin, $allowedOrigins)) {
            return $next($request)->header('Access-Control-Allow-Origin', $origin);
        }

        return $next($request);
    }
}

Settings Synchronization via chrome.storage.sync

// Synchronize settings with server and chrome.storage.sync
async function syncSettings() {
  // Load from server
  const serverSettings = await apiRequest('GET', '/v1/user/settings');

  // Save locally
  await chrome.storage.sync.set({ settings: serverSettings });

  return serverSettings;
}

// When settings change — save to server
chrome.storage.sync.onChanged.addListener(async (changes) => {
  if (changes.settings) {
    await apiRequest('PUT', '/v1/user/settings', changes.settings.newValue);
  }
});

Offline Mode Handling

const PENDING_ACTIONS_KEY = 'pending_actions';

async function executeOrQueue(action) {
  try {
    await fetch(action.url, action.options);
  } catch (error) {
    // No connection — queue the action
    const pending = (await chrome.storage.local.get(PENDING_ACTIONS_KEY))[PENDING_ACTIONS_KEY] || [];
    pending.push({ ...action, queued_at: Date.now() });
    await chrome.storage.local.set({ [PENDING_ACTIONS_KEY]: pending });
  }
}

// Execute pending actions when connection is restored
chrome.runtime.onStartup.addListener(flushPendingActions);

Timeline

REST API extension integration with synchronization and offline support: 4–6 business days.