PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.03k stars 346 forks source link

[BUG] Uncaught Error: Extension context invalidated. #873

Open aiddroid opened 7 months ago

aiddroid commented 7 months ago

What happened?

A bug happened! So many errors. I don't know why.

background.ts

import browser from 'webextension-polyfill'

browser.contextMenus.removeAll();
browser.contextMenus.create({
    id: 'test',
    title: "test",
    contexts: [
        "image",
    ]
});

browser.contextMenus.onClicked.addListener(function(info, tab) {
   // TODO
   browser.tabs.sendMessage(tab.id, {...});
});

content.ts

import browser from 'webextension-polyfill'

browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    // Do some thing with promise.
    fetch('/api').then((res) => {
             // TODO
    }).catch();

    return true;
});

errors in file content.480c00a3.js:328

image

Version

Latest

What OS are you seeing the problem on?

No response

What browsers are you seeing the problem on?

No response

Relevant log output

No response

(OPTIONAL) Contribution

Code of Conduct

deveshlashkari commented 6 months ago

I faced the same issue while add content script. I followed everything written in documentation and still get the error :

image

Basically, I just added a console.log to check if the script is getting loaded or not. But, here is the hack. The script loads successfully its just that I was looking into the wrong console.

When you load the script, all the updates will be visible in Tabs Console not in the Extension's Console. Please check the Tabs console. I have just ignored the error. Everything is working fine.

JesseCHN commented 4 months ago

the same issue +1

jiweiyuan commented 4 months ago

the same issue +1

Jonathan-Asher commented 4 months ago

the same issue +1

hhmy27 commented 3 months ago

same

toFrankie commented 2 months ago

+1

Related?: How to avoid "Extension context invalidated" errors when messaging AFTER an Extension update?