Change badge text from content_script.js

I want to change the text for the browserAction icon but I can’t get it to work.

content_script.js

browser.browserAction.setBadgeText({text: "Hello"});

Can someone help me out?

Thanks

1 Like

You can not access the browserAction API from content scripts:

1 Like

Here is a very simple way to accomplish what you need.

extension.zip (11.9 KB)

As you can see inside the code, you need to send a message (via browser.runtime.sendMessage) from your content script to your background page to access the browserAction API.

1 Like

Thanks for the help! I got it working!
The extentsion.zip was really helpful.