D
D
dollar2019-04-18 14:34:42
JavaScript
dollar, 2019-04-18 14:34:42

How to fix chrome.runtime.sendMessage on extension update?

The function inside the script content starts to return an error when used.
Error:
Uncaught Error: Extension context invalidated.
It is possible to wrap it in a try, but the function remains broken, although the updated extension works fine and is ready to receive messages. Reloading the page is not a pretty solution (the user can type text on the site that will be lost).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Polyakov, 2021-10-03
@polRk

It is necessary to unsubscribe from all events and call.
chrome.runtime.reload()
It is convenient to share via Port, It has an onDisconnected event, and that's where you can call reload ()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question