Problem with internationalisation management

This is a copy of a post I made on reddit r/FirefoxAddons/, I’ve been advised to also post here so here we go.

Being fairly new to development, I made a test addon with a background script containing a non-ascii character (an accent) in its name. It simply creates a browser action button that makes a console log when clicked.

It’s working, but I added a similar listener for onStartup and this one is never called (I did make an xpi to install as an addon that will remain on restart of Firefox, so that onStartup gets fired). Problem is solved when I remove the accent from the background script name (and modify the manifest accordingly).

So it would appear that the character set of the script name doesn’t usually matter, except on profile startup (and maybe other circumstances). Could this be on purpose ?

Of course I can simply use ascii characters for names, but I think the question is interesting, especially for us foreigners.

Can you upload your test extension?

Are you sure you need onStartup handler?
Fired when a profile that has this extension installed first starts up.
So it won’t fire when you install or update your extension - just to be sure you understand the consequences :slight_smile: .

Also, are you checking the right console? (just checking :slight_smile: )
Sometimes, some logs gets “lost”, try the Browser console (Ctrl + Shif + J) in the “Multiprocess” mode.
I refuse to believe a special character would break anything these days…

Yes I’m watching the right console :slight_smile:

I should mention that I’m testing all this on Nightly with unsigned extensions authorised.

Well as I had already deleted the test, I tried to remake it.

Without accent, all 3 listeners perform as intended (btw, I added an alert just to raise a warning and have it more visible than just a log).

But this time nothing works with accented file name, it’s more consistent I suppose.

Strange thing though : when using “This Firefox” to add the same accented version, onClicked and onInstalled work this time. Of course this way I can’t test for onStartup. Which makes me wonder if the way I create xpi files is correct. currently I’m using 7zip to get a zip and just rename this one to xpi.

As a new user, I can’t upload files for you to try out, so here’s the code. All indentation was removed when pasting. I used a free icon found on the web just to have something to display.

manifest.json :

{
“manifest_version”: 3,
“name”: “test”,
“version”: “1.0”,

“description”: “Test’”,

“browser_specific_settings”: {
“gecko”: {
“id”: “test@test.com”,
“data_collection_permissions”: {
“required”: [“none”]
}
}
},

“icons”: {
“96”: “icons8-courrier-94.png”
},

“action”: {
“default_icon”: “icons8-courrier-94.png”,
“default_title”: “Test”
},

“background”:
{
“scripts”: [“derrière.js”]
}
}

derrière.js :

browser.action.onClicked.addListener(() => {
console.log(‘test bouton’);
});

browser.runtime.onInstalled.addListener(() => {
console.log(‘test install’);
});

browser.runtime.onStartup.addListener(() => {
alert(‘test startup’);
console.log(‘test startup’);
});

On runtime.onStartup it says:

Note: When using an event page or background service worker, the extension must add a listener to runtime.onStartup on the event page for the event page to be executed at least once per browser session.

But like you said, I’m not sure why the extension would need to run code if it hasn’t actually been activated…

Well the purpose of this addon is to perform tests to better understand addon development. So I’m testing onStartup too.

Unfortunately, I can’t reproduce the problem on my computer.

I’m running Linux Mint 22.3 with FF Developer Edition 151.0b6.
Linux Mint doesn’t appear to have the FF Dev Edition in its repos, so I:

The only problem I can see when I inspect the extension in about:debugging#/runtime/this-firefox is:

alert() is not supported in background windows; please use console.log instead. derrière.js:10:8
test startup derrière.js:10:8
test startup derrière.js:11:11

(Even though alert() isn’t supported in background scripts, calling it doesn’t “crash” the background script.)

On my system, it also works with different non-ASCII characters in the background script’s file name, e.g. when I name it bäckgröünd.js

What operating system and FF version(s) are you using?

Indeed I should have indicated that I’m on windows 10, with latest Nightly.

Maybe it’s something on my end then ? More likely I suppose. But the fix is easy : just use ascii characters in file names.

When pasting code here, place triple backticks (```) on the line above and below the code, that will activate code format that keeps indentation and empty spaces.

Also, I’ve just noticed - to my surprise - I’m using this event listener in many of my extensions, like this:

// NOTE: in MV3 the background script won't start without onStartup (or similar) listener
browser.runtime.onStartup.addListener(() => {});

Yeah, it’s a dummy listener that only forces browser to execute the background script when the browser starts. Otherwise browser would start the background script only when actually needed.

If you want to let Mozilla know about the problem, you can report it on the Bugzilla Main Page

I couldn’t find any bugs about background script file names, but FF and other Mozilla software seems to have problems with non-ASCII / accented characters, so maybe it isn’t just on your end…

Maybe I’ll create a bug, thanks for the advice.

And thanks juraj.masiar for the hint.