Evgeniy
Evgeniy

Reputation: 2605

How to setTitle, containing words and variable?

I want to setBadge and setTitle like

chrome.browserAction.setBadgeText({text: String(badgeText)});
chrome.browserAction.setTitle({text: "The number "+currentDomain+ "is "+ String(badgeText)});
chrome.browserAction.setBadgeBackgroundColor({ color: '#1d2554' });

But in the title remains the title, which is set in the manifest, and the badge color becomes default blue. As error i'm getting

Uncaught TypeError: Error in invocation of browserAction.setTitle(object details, optional function callback): 
Error at parameter 'details': Unexpected property: 'text'.

What i'm doing wrong? What is the correct syntax for this?

PS: Existence of default_title in the manifest doesn't play a role - if it isn't set, the title shows the name from manifest, but not the title i set in background.js.

Upvotes: 0

Views: 141

Answers (1)

Gergely Szabo
Gergely Szabo

Reputation: 899

It should be title instead of text, like: chrome.browserAction.setTitle({title: "The number "+currentDomain+ "is "+ String(badgeText)}); https://developer.chrome.com/extensions/browserAction#method-setTitle

Also you might want to make it more readable by using template literals, so it would be: {title: `The number ${currentDomain} is ${String(badgeText)}`}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Upvotes: 1

Related Questions