# Console: Uncaught Error: Extension context invalidated (extension was updated or reloaded)

**Code:** `Extension context invalidated` · **Category:** Browser · **Seen on:** Chrome, Edge, JavaScript

A content script from an extension kept running after the extension was reloaded, updated or removed, so its link to the extension is broken.

## Meaning

Open tabs keep the old content script alive. When the extension updates, calls such as `chrome.runtime.sendMessage` throw this error until the page is reloaded. Users fix it with a refresh; extension authors should catch it and stop their script cleanly.

## Common causes

- Extension updated or reloaded while the page stayed open (very common in development)
- Extension disabled or uninstalled
- Service worker (Manifest V3) restarted and state lost
- Long-lived port closed
- Orphaned content script calling `chrome.*` APIs

## Quick fix

1. Reload the page (and the extension during development)
2. Extension authors: wrap `chrome.runtime` calls in `try/catch` and detect `chrome.runtime?.id`
3. Re-inject the content script after an update

## Detailed fix by platform

### JavaScript

1. `if (!chrome.runtime?.id) { cleanup(); return; }` before calling extension APIs; wrap `sendMessage` in `try { ... } catch (e) { if (/Extension context invalidated/.test(e.message)) cleanup(); }`

### Chrome

1. `chrome://extensions` → reload the extension, then reload the open tabs

## How to diagnose

1. **Timing** — Did the extension update or reload?
2. **Tab** — Is the page older than the extension?
3. **Code** — Own extension?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/browser/extension-context-invalidated)
