Bug: Reopen-closed-tab via extensions stops working after opening a link from an external software directly into a container
Status: VERIFIED
Priority: P2
Resolution: FIXED
Created: 2023-04-20 15:06:47+00:00
Resolved: 2023-05-15 09:52:14+00:00

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0
Build ID: 20230420092216

### Steps to reproduce
#### Prerequisites
1. In a new profile, install any extension that can reopen a closed tab, e.g. [Undo Close Tab](https://addons.mozilla.org/firefox/addon/undoclosetabbutton/) (UCT).
2. Install any extension that can auto-reopen a tab into a (different) container, e.g. [Facebook Container](https://addons.mozilla.org/firefox/addon/facebook-container/)[1]. 
3. Check if reopening a closed tab is still working at this stage:
3a. Open a dummy tab so browser does not quit after closing all other tabs.
3b. Open https://www.facebook.com, or any link, from within Nightly.
3c. Close the tab in 3b.
3d. Click UCT extension icon to reopen last closed tab.
3e. 3b should reopen at this stage.

#### Reproducing the bug
4. Open https://www.facebook.com from any external software to the above Nightly profile. I use WordPad (not Notepad) and paste https://www.facebook.com in a document. (Or open any link that will auto-open in a container, if Facebook Container extension is not used.)
This Facebook tab should open in a Facebook container.
5. Close this tab. Remember to keep a dummy tab.
6. Click UCT extension icon.

[1]: For some reason Facebook Container cannot be used for bisecting in Mozregression GUI because the first Facebook tab - triggered by mozregression's `URL` field - does not open in a container. Please use Firefox Multi-Account Containers instead and set up accordingly.
Facebook Container can be used in a locally installed Nightly.

### Actual results
The facebook tab does not reopen. Actually all subsequent closed tabs, originated from within or outside Nightly, cannot be reopened.
Browser Console shows these errors after clicking UCT:

```
can't access property "url", entry is undefined ext-browser.js:911
    convertFromSessionStoreClosedData chrome://browser/content/parent/ext-browser.js:911
    getRecentlyClosed chrome://browser/content/parent/ext-sessions.js:46
    getRecentlyClosed chrome://browser/content/parent/ext-sessions.js:138
    InterpretGeneratorResume self-hosted:1551
    AsyncFunctionNext self-hosted:948
```
```
Error: An unexpected error occurred undefined
```

I can, however, reopen closed tabs by the native `Reopen Closed Tab` command in tab bar's context menu, or `Ctrl-Shift-T`.

### Workarounds
I can restore the reopen closed tabs function by:
1. quitting Nightly and start a new session. If the previous session had triggered the bug, it will carry over once I restore this session. Or
2. opening a new window then close the window that has the tab opened externally. The reopening function restores immediately.

### Notes
I tested few other extensions that do not work in this case:
#### Undo tabs
[Undo Closed Tabs Button](https://addons.mozilla.org/firefox/addon/undo-closed-tabs-revived/)
[Foxy Gestures](https://addons.mozilla.org/firefox/addon/foxy-gestures/) (draw a gesture to reopen a tab)
#### Auto-reopen tabs in a container
[Temporary Containers'](https://addons.mozilla.org/firefox/addon/temporary-containers/) `Automatic Mode`
[Firefox Multi-Account Containers'](https://addons.mozilla.org/en-GB/firefox/addon/multi-account-containers/) `Always Open This Site in…`

### Regression
Last good Nightly: 2023-04-13
First bad Nightly: 2023-04-14
pushlog: https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=5c9aa60ea6f47114a9367f56c50cd13299aa1d29&tochange=7011cafe7d2c47b84c7437e856809945cd5c77ba

Bisecting autoland builds: https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=e55b487ddf10347934259b4771ed922174a56c62&tochange=fb24fd4183358d0c91f5878cf446623f835d4be8

This is regressed by bug 1824040.