chrome.i18n.getMessage not a function

1,300 views
Skip to first unread message

Jason Savard

unread,
Feb 9, 2021, 6:24:46 PM2/9/21
to Chromium Extensions
I am testing using the "service_worker" in manifest v2 in preparation for v3.

But it seems the getMessage function does not exist from within the context of a Chrome extension's service worker. Is there an alternative?

My use case is simple I generate a context menu which needs to be internationalized.

Note: It does exist and work from within other extension pages.

Jackie Han

unread,
Feb 9, 2021, 10:15:46 PM2/9/21
to Jason Savard, Chromium Extensions
You're right. I searched a bit and found that someone has already reported this issue.
See #1175053 and #1159438 

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/6c8b3b99-8a19-4e3f-9b38-ebf2e5f4e9c5n%40chromium.org.


--
Jackie Han

Simeon Vincent

unread,
Feb 10, 2021, 9:52:49 PM2/10/21
to Jackie Han, Jason Savard, Chromium Extensions
Thanks for calling out those bugs, Jakie. I just passed them to a colleague to hopefully get eyes them soon.

Cheers,

Simeon - @dotproto
Chrome Extensions DevRel


Kamer DINC

unread,
May 2, 2021, 5:14:11 PM5/2/21
to Chromium Extensions, Simeon Vincent, Jason Savard, Chromium Extensions, Jackie Han
Any update about this issue? 
Im still getting error from background service worker.

Jackie Han

unread,
May 11, 2021, 1:57:55 AM5/11/21
to Kamer DINC, Chromium Extensions, Simeon Vincent, Jason Savard
chrome.i18n.getMessage() is a sync method that needs to read files, so I guess it's not suitable for (async) service workers.

Workaround is not difficult, just don't use it, use your custom method. Basically like this:
1. write your getMessage(key) function, that returns a string from memory or fetch from local files.
2. use navigator.language to decide which language to use.

Kamer DINC

unread,
May 14, 2021, 6:46:13 AM5/14/21
to Chromium Extensions, Jackie Han, Chromium Extensions, Simeon Vincent, Jason Savard, Kamer DINC
Thanks a lot. I will try it

Carlos

unread,
Oct 3, 2021, 6:23:20 AM10/3/21
to Chromium Extensions, kame...@gmail.com, Jackie Han, Chromium Extensions, Simeon Vincent, Jason Savard
@Jackie Han Using navigator.language or chrome.i18n.getAcceptLanguages is not gonna provide the same result. As chrome.i18n.getUILanguage and chrome.i18n.getMessage use the language of the browser itself. Not the languages websites are requested in.

In addition, going for a fetch to _locales won't consider language fallbacks. Currently getMessage can go from es_419 to es to en. And many webextension authors make use of this fallback mechanism to reduce the extension package size.

Supporting chrome.i18n.getMessage has been proposed in the w3c webextension group. See:
https://github.com/w3c/webextensions/issues/93

Op vrijdag 14 mei 2021 om 12:46:13 UTC+2 schreef kame...@gmail.com:

GroupNinja Official

unread,
Oct 6, 2021, 7:46:45 AM10/6/21
to Chromium Extensions, Jason Savard
Hey jason i use your extension "Explain and send screenshots" i need help one person submitted fake dmca report and now my extension is down i submitted the counter notice but it will take 10 days 

and even then i do not know if he can just put another fake dmca report 

what to do?

Jackie Han

unread,
Oct 7, 2021, 9:31:20 AM10/7/21
to Carlos, Chromium Extensions, kame...@gmail.com, Simeon Vincent, Jason Savard
Carlos,

So I said it's a workaround method (if there is no other way), and didn't say it is exactly the same implementation mechanism.

The browser UI language is usually the language of the operating system or specified by the browser's startup parameter.

navigator.language(s) is also usually the languages of the operating system by default and users can customize them in the browser settings(chrome://settings/languages). This is also used for the Accept-Language HTTP header.

Although navigator.language may be different from the browser UI language, it is still an acceptable language for users.

Compared with the front pages, the service worker or background page usually requires a small number of messages. So developers can write messages in JS code directly if they don't use chrome.i18n.getMessage() .

By the way, chrome.i18n.getMessage() can't support passing a preferred language as a parameter. If you want to let users change your extension's language independently (don't change browser UI language or OS language), you can't rely on chrome.i18n.getMessage().
Reply all
Reply to author
Forward
0 new messages