4

Can anyone explain the lifecycle of browser extensions in Chrome/Firefox? More specifically, I'm looking for what exactly happens when the onStartup and onSuspend events are triggered, and what triggers them. Here are a few different answers I'm looking for:

  • When onStartup is triggered, will it automatically inject content scripts into all open tabs, or do I have to do that manually?
  • How is onStartup triggered once an extension has gone inactive? Is it just clicking the browserAction icon, or are there other ways to trigger it?
  • What triggers onSuspend? Does it just time out after a certain amount of inactivity?
  • Is there a way to prevent onSuspend from triggering (besides setting persistent: true in the manifest)? What if I keep a port open, rather than using sendMessage to communicate?
  • 1
    A bit of prior research could go a long way here. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions – Robert Harvey Feb 06 '19 at 15:36
  • 1
    and https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onStartup. In general, events don't do anything by themselves; you have to hook them and then execute some code when they fire. – Robert Harvey Feb 06 '19 at 15:39
  • 2
    @RobertHarvey I've done more than a bit of prior research. Linking to a general page to answer specific questions that I haven't been able to find on that exact page is hardly helpful. As to your next comment, maybe a bit of clarification will help— I've hooked them up already, I just want to know exactly what's happening to my scripts when they are fired. For example: I know `onSuspend` unloads my background scripts, but what else? Just looking for a more specific breakdown of the lifecycle than what exists in any documentation I've been able to find. – Cassandra O'Connell Feb 06 '19 at 15:48
  • 1
    My point is that the community can't help you if they have to play twenty questions figuring out what you've tried so far. Where does it say that `onSuspend` unloads background scripts? Unless there's some documentation that tells me otherwise, events *don't actually do anything* except provide a hook for your own code to execute. – Robert Harvey Feb 06 '19 at 15:57
  • So what's happening to your scripts is that they are being executed. They'll do whatever the code you wrote says they'll do. – Robert Harvey Feb 06 '19 at 16:01
  • 2
    @RobertHarvey I don't think you're understanding what I'm asking. I'm only wondering what happens to fire those events in the first place... so, what are the exact steps that happen in Chrome/Firefox when an extension is started/suspended. The documentation provides enough information to tell me that events will fire for each of those processes, just not exactly what those processes entail. I'm only answering your comment to clear up any confusion for future answerers... I don't think you can answer my question. Thanks for your time, but I'll wait on others to answer. – Cassandra O'Connell Feb 06 '19 at 16:07

0 Answers0