Addon only executes after restart

(Juanma1980) #1

I’m developing a simple addon for my organization (installed via the distribution folder).
The addon simply adds a few bookmarks to Firefox. It’s active at first load of firefox but bookmarks are only added when user restarts firefox.
I’ve seen another threads with a similar issue ( ie: Need to restart browser on first time add-on installation ).
I can see that the extension is present on the user’s profile folder on first run but for any reason - i don’t understand why - it only adds the bookmarks on second launch.

If the addon is manually installed works like expected (it’s installed and the bookmarks get generated).
The addon is a webextension, is signed and works, but only after the first launch.

I’ve tried on firefox 57 & 58 with same results… I’m sure that I’m loosing something. Any idea?

(Martin Giger) #2

How/when are you adding those bookmarks?

(Juanma1980) #3

Thx for your answer.
Well. The “how” is with the bookmarks api (bookmarks.create).
The “when”… well I’ve no idea. It’s a background plugin and permission to modify the bookmarks is granted throug the manifest.json.
The same plugin in Chromium/Chrome works as expected, really in firefox also works but only after the first restart.

I think that when firefox launches it loads the plugin but I don’t know if perhaps there’s a race condition or is the default behavior that makes the browser “activates” the plugin but don’t “executes” it. The fact that the plugin is present in the user’s folder at first launch, that firefox shows the plugin as loaded and the bookmarks aren’t created points me to, possibly, a race condition (or default behavior, I don’t know but I need this to work as expected or my boss will put a horse’s head into my bed xD xD)

p.s. I’m sorry I didn’t reply sooner, I’ve been busy with personal affairs

(Juanma1980) #4

More info:
If I execute firefox with the flags “–jsconsole --jsdebugger” then the addon works as expected on first time.
If I execute the firefox without flags then the addon is loaded but not executed until I restart Firefox. Perhaps is there any race condition?

(Martin Giger) #5

I can’t believe that the JS in the background isn’t executed when installed. Have you checked if any code in your background page is ran?

(Juanma1980) #6

Thxs for your interest.
Well, after a few attempts I think that I know what’s going up. I will try to explain:
My addon generates the bookmarks at the bookmark’s toolbar. When I launch firefox I see an error about a parentGuid non existing (I believe is the bookmark’s toolbar, so my addon is executed). If I open the bookmark’s menu the faster I can I see that the bookmarks are not loaded (the default bookmarks), they take a moment to show and until that moment the bookmark’s menu is empty and in the console debug I see the “parentGuid” error appear.
The problem here - i believe - is that my plugin works but 'cause we’re deploying the addon with our firefox install the addon must wait until the bookmark’s folders are fully populated.

If I know how I’ll link here a video with the “visual proof” but I’will try that approach and if it works I will let you know.


(Juanma1980) #7

Well, this was my first attempt to build a firefox’s extension and I’m not very proud of my work…
Finally it’s working as expected but… when the addon finalizes its execution it checks if the custom bookmark that we want to add exists, if it’s not the case then reloads the extension.
It’s working but… well, I know it’s a botched way for make the thing works…