I recently added a configuration screen to an extension, the (simplified) layout looks like this:
Code: Select all
myAddon/myAddon.js:
myAddon = {
someFunction: function(){
alert('some function')
}
}
myAddon/info.json:
{
"config": "config.js",
...
}
myAddon/config.js:
localRequirejs('myAddon')
window.configInfo = {
load: function(panel, addon){
panel.innerHTML = [some html code];
myAddon.someFunction();
}
}
Checking the function, it looks like localRequirejs internally calls requirejs with the __scriptName parameter (among others).
I updated the load function to do the following:
Code: Select all
load: function(panel, addon){
console.log("__scriptName:"+ __scriptName)
console.log("addon:")
console.log(addon.title)
console.log(addon.ext_id)
console.log(addon.configFile)
}
__scriptName returns a completely different addon. When calling __scriptName from other locations, e.g. the directly in the script file, it works fine. It seems like this only happens when the variable is accessed from a context that's not the main window.
Now, I'm not sure if I'm even supposed to use localRequirejs instead of requirejs with an explicit path here, the behavior just seems weird.
Update:
I did some more testing and found the following
- If I remove all scripts but the one with the config.js file everything works fine. Which can probably be expected because there is no other extension that could provide a wrong path.
- The exception doesn't occur if there are only few extensions, but it happens eventually if I gradually add more extensions.
- __scriptName will always provide the same (wrong) addon if the same addons are loaded, but it's not related to one specific addon e.g. if __scriptName returns extension A once, it will always return that specific extension. If I delete extension A, __scriptName will return another (seemingly) random extension - but it will always return that same other extension. What I'm trying to say is that the loaded extension is, while incorrect, still deterministic, not completely random.
- I made sure to also test this for addons that are included by default, not the ones I wrote. The result remains the same.