Closed Bug 1654668 Opened 5 years ago Closed 5 years ago

Calling "browser.runtime.getBackgroundPage" fails if background script gets reloaded and if it contains "browser.menus.create"

Categories

(WebExtensions :: General, defect)

79 Branch
defect

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: juraj.masiar, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0

Steps to reproduce:

  1. load attached extension
  2. new tab will be opened

Actual results:

It will print following text while trying to execute browser.runtime.getBackgroundPage():
OK
Error: An unexpected error occurred

Expected results:

It should print:
OK
OK

It will print this if you delete browser.menus.create from background script.
I have no idea why these thing are related at all. The background script will be executed without throwing any exceptions, but something will get broken.

I don't know if Firefox can reload my background script, but I've been getting some error reports from users running 32 bit version so I suspect that Firefox will reload my background script to save some resources which then causes this bug because of the context menus I'm creating.

Why do you call location.reload() in the background script? Firefox will not reload your background page, so if you're trying to simulate something else that you think is happening inside the browser, you're probably looking in the wrong place.

Flags: needinfo?(juraj.masiar)

Can you be 100% sure there is no way a background script will ever get reloaded? Maybe during the addon upgrade, browser upgrade or if Firefox runs out of memory or because of some other bug?

Also note that this bug is not happening in ESR 68 or Chrome.
(to test it in ESR you have to remove numeric separators from my example code, like: 1_000)

I know that reloading background script is not normal :), but should it really break something?

Flags: needinfo?(juraj.masiar)

(In reply to juraj.masiar from comment #2)

Can you be 100% sure there is no way a background script will ever get reloaded? Maybe during the addon upgrade, browser upgrade or if Firefox runs out of memory or because of some other bug?

For a browser update, the entire browser (including all extensions) is shut down and restarted. During an addon update, the entire addon is shut down and restarted, these are both different from reloading one page while the rest of the extension continues to run. And when Firefox runs low on memory, I don't believe that "reload pages" is one of its strategies for recovering.

Also note that this bug is not happening in ESR 68 or Chrome.
(to test it in ESR you have to remove numeric separators from my example code, like: 1_000)

If this was working differently in 68, it would be helpful to pinpoint when it changed using mozregression.

I know that reloading background script is not normal :), but should it really break something?

This is unexpected behavior, but with all the other work going on, its unlikely that anybody will spend any meaningful time on it if the scenario is so unusual.

What Andrew said, Firefox will never reload your background page, only the extension can do that to itself. We might add a feature where background page is closed, and later re-opened (if the extension opts in), but if we do, we'll certainly make sure that works as expected, and add a test similar to that effect.

While ideally this could work, I don't see much of a point, so closing this as WONTFIX instead of setting a low priority and forgetting about it.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: