Injecting content scripts in existing pages

I’m pretty new to WebExtensions, and have just developed my first real one. In the process, I ran into one problem with injecting content scripts into already loaded pages. Or perhaps it only happens when installing/enabling the extension.

The problem (if the script is declared in the manifest) is that the message manager doesn’t seem to be ready as soon as the script is able to call it, and this can and normally does cause it to fail. This might not be a big deal, except I can’t find a really good way to know when it’s safe to use it. What I ended up doing is catching the exception and trying again after some amount of time. In this sense, I solved the problem. However, I am not fully satisfied, as it feels like a bit of a kludge. I think there should be an event for it on the runtime API, or something along those lines. What do you think?

Also, the script doesn’t run at all in existing pages if I use contentScripts.register(). Is it supposed to work this way? I can’t tell, because unless I missed something, the docs are completely silent on this matter, as well as the above one.