Best method to debug browser.runtime callbacks?

(Arunava) #1

Hey Mozillians!
What’s up?

I need some clarification here.
How do you guys debug the callbacks from browser.runtime ?
browser.runtime.onStartup() in specific.

To test an extension, I load it from about:debugging
If I reload it, it triggers the browser.runtime.onInstalled() callback.

Not sure, if it triggers the browser.runtime.onStartup().

But that’s is the method I know, right now to trigger callbacks from browser.runtime

What’s a better approach?

Thanks in advance.
Have a nice day :slight_smile:

(Juraj Masiar) #2

Good question. From the documentation on runtime.onStartup:

Fired when a profile that has this extension installed first starts up.

So reloading extension should not trigger it.

Regarding the debugging - this is something I would like to know as well, because all I can think of is wrap the body of the onStartup function into:
setTimeout(() => { /* your handling code */ }, 9000)
and then register the breakpoint in 9 seconds :slight_smile:
Also you will need to start your browser with your extension installed, for that you should be able to use web-ext tool.

(Martin Giger) #3

There’s also this handy guide for how to test things:

(Arunava) #4

I Kind of was thinking the same about debugging the onStartup() method.

All I needed was to start firefox with the extension installed.
So, thanks for the link. Very helpful tool. I needed it. :slight_smile:

(Arunava) #5

Thanks for the guide.
It’s really helpful.