Closed Bug 1741694 Opened 4 years ago Closed 2 months ago

browser.search.search() doesn't work reliably with fission enabled

Categories

(Core :: DOM: Content Processes, defect, P3)

Firefox 94
Desktop
Unspecified
defect

Tracking

()

RESOLVED WORKSFORME
Fission Milestone Future
Tracking Status
firefox-esr91 --- disabled
firefox94 --- affected
firefox95 --- affected
firefox96 --- affected
firefox147 --- ?
firefox148 --- ?
firefox149 --- fixed

People

(Reporter: robbendebiene, Assigned: aiunusov)

Details

(Whiteboard: dom-lws-bugdash-triage)

Attachments

(3 files)

With fission enabled (fission.autostart = true) the search engine API sometimes doesn't work.

Using the following manifest.json and background.js:

{
  "manifest_version": 2,
  "name": "Test",
  "version": "1",
  "permissions": [
    "search"
  ],
  "background": {
    "scripts": [ "background.js" ]
  },
  "browser_action": {
    "default_title": "Test"
  }
}
browser.browserAction.onClicked.addListener(async () => {
  const [ activeTab ] = await browser.tabs.query({active: true});
  
  const searches = await browser.search.get();
  
  const tab = await browser.tabs.create({
    openerTabId: activeTab.id,
    url: "about:blank",
    active: true
  });
	
  const randomSearchEngine = searches[Math.floor(Math.random()*searches.length)];
	
  browser.search.search({
    query: "Search query",
    engine: randomSearchEngine.name,
    tabId: tab.id
  });
});

When clicking the browser action the newly opened tab will sometimes stay blank instead of switching to the search query.

Hello,

I reproduced the issue on the latest Nightly (96.0a1/20211118212756), Beta (95.0b9/20211118185700) and Release (94.0.1/20211103134640) under Windows 10 x64 and Ubuntu 16.04 LTS.

With fission.autostart = false, the first click on the browser action will yield a blank tab, however, every subsequent click on the browser action will open a tab with the search query.

With fission.autostart = true, each second click on the browser action will yield a blank tab i.e. 1st click=search query, 2nd click=blank tab, 3rd click=search query, 4th click=blank tab etc.

For more details, see the attached screenshots.

Status: UNCONFIRMED → NEW
Ever confirmed: true

Hey Mark, can you please take a look into this?

Flags: needinfo?(standard8)

I believe this is tab browsing rather than search related.

As far as I can tell what gets passed through to openLinkIn is consistent and correct (called from here). It always has the correct search urls, and is indicating to load in the current tab.

If I add a breakpoint in ext-search.js, e.g. here, then the issue goes away - at least in the non-fission case.

This makes me think it is process switching related & timing. Since Fission is likely to be changing processes more often, this would seem to back up the idea.

I'm wondering if Mike might be able to look into this, or know who to pass it onto.

Flags: needinfo?(standard8) → needinfo?(mconley)
Fission Milestone: --- → Future

This is really easy to reproduce by creating an add-on from the things in comment 0.

From what I can tell using rr, what's going on is that we attempt to load the search result page in a process that goes away soon after...and the new process that gets created tries to load about:blank.

So I think this is deeper DOM process switching stuff. I think I'm going to see if Nika has any idea what's going on here.

Flags: needinfo?(mconley) → needinfo?(nika)

(In reply to Mike Conley (:mconley) (:⚙️) from comment #6)

From what I can tell using rr, what's going on is that we attempt to load the search result page in a process that goes away soon after...and the new process that gets created tries to load about:blank.

If you can reproduce with rr, can you post a pernosco trace for me to look into? It would be useful for following it through.

We've got the process switching stuff down pretty well at this point, so it sounds like we're perhaps attempting to load the search result page and then some other code (perhaps extension code?) is cancelling the load during the process switch? An about:blank in the new process after the process switch which is quickly replaced is expected.

Flags: needinfo?(nika) → needinfo?(mconley)

Sorry for the delay - Pernosco session is here: https://pernos.co/debug/3S2g3Kl1x83kcssQcqkvsg/index.html

Flags: needinfo?(mconley)

The severity field is not set for this bug.
:mixedpuppy, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(mixedpuppy)

Nika, can you validate Mike's thoughts?

Flags: needinfo?(mixedpuppy) → needinfo?(nika)
Component: General → IPC
Product: WebExtensions → Core
Component: IPC → DOM: Content Processes

Would you mind verifying if the STR still apply? In case we should probably capture a new pernosco session, too.

Flags: needinfo?(nika) → needinfo?(aiunusov)

Managed to reproduce.
At least, I see this in the logs, when search is interrupted and page is blank:

"WebProgress Ignored: no longer current window global: file C:/Users/aiunu/mozilla-source/mozilla-unified/dom/ipc/BrowserParent.cpp:3141"

https://searchfox.org/mozilla-central/source/dom/ipc/BrowserParent.cpp#3141 ("The current process for this BrowsingContext may have changed since the notification was fired")

Flags: needinfo?(aiunusov)
Assignee: nobody → aiunusov
Attached file background_2.0.js

However, the problem may be in the extension code itself. Because using the latest official MDN documentation I was able to create an extension that works like a charm (using disposition: "NEW_TAB"):

function search() {
    browser.search.get().then(function(searches) {
        const randomSearchEngine = searches[Math.floor(Math.random() * searches.length)];
        browser.search.search({
            query: "Search query",
            engine: randomSearchEngine.name,
            disposition: "NEW_TAB",
        });
    });
}
browser.browserAction.onClicked.addListener(search);

Would this solution be enough? Because the search itself does not seem to be broken.

Flags: needinfo?(robbendebiene)
Flags: needinfo?(jstutte)

Thanks for investigating the problem.
Using disposition: "NEW_TAB" might be a solution for some add-ons, but in Gesturefy the user can define the placement of the new tab
(see code). This is why the tabId is required. Back then when the API was first introduced this was the recommended way and also worked without any problems.

Flags: needinfo?(robbendebiene)

Thanks for the feedback.
Got it. I will take a look into the problem closely, to figure out why the process goes away (or changes) for the new tabId

Severity: -- → S3
Status: NEW → ASSIGNED
Priority: -- → P3

I changed a bit your example. And it started working fine

browser.browserAction.onClicked.addListener(async () => {
  const activeTab  =  browser.tabs.getCurrent();
  
  const searches = await browser.search.get();
  
  const tab = await browser.tabs.create({
    openerTabId: activeTab.id,
    url: "about:blank",
    active: true
  });
	
  const randomSearchEngine = searches[Math.floor(Math.random()*searches.length)];
	
  browser.search.search({
    query: "Search query",
    engine: randomSearchEngine.name,
    tabId: tab.id
  });
});

(So, I am suspecting browser.tabs.query({active: true}) is causing issue)

Perhaps it is important to note that for me the problem only occurred after having several tabs open. E.g. with less than 7 tabs everything worked but having more than 7 caused the problem. Therefore I thought it must be some sort of race condition.

with browser.tabs.query({active: true}) every second click on extension leads to the blank page
with browser.tabs.getCurrent() it works fine in 100% cases

(I will take a look on rr traces and create a follow up bug)

Flags: needinfo?(jstutte)

(still an issue)

sometimes browser.tabs.query({active: true}) does not work properly when fission is enabled

Whiteboard: dom-lws-bugdash-triage

I double checked everything, so

browser.tabs.query({active: true}) always returns correct tab
then, new tab is created

but search() sometimes does not work with that tab
My workaround is working, because openerTabId is always undefined (means, browser.tabs.getCurrent() returns undefined)

(checking regression window)

Not reproducible anymore
This may be fixed due to recent improvements to about:blank handling.

Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: