Bug 1698842 - [devtools] Avoid a few cases where targetFront is null during a client side target switching. r=nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D108680
This commit is contained in:
Alexandre Poirot 2021-03-18 16:28:29 +00:00
Родитель c261f0be80
Коммит be9a714771
2 изменённых файлов: 26 добавлений и 15 удалений

Просмотреть файл

@ -195,19 +195,26 @@ class TabDescriptorFront extends DescriptorMixin(
}
this._targetFrontPromise = (async () => {
let targetFront = null;
let newTargetFront = null;
try {
const targetForm = await super.getTarget();
targetFront = this._createTabTarget(targetForm);
await targetFront.attach();
newTargetFront = this._createTabTarget(targetForm);
await newTargetFront.attach();
} catch (e) {
console.log(
`Request to connect to TabDescriptor "${this.id}" failed: ${e}`
);
}
this._targetFront = targetFront;
// Completely ignore the previous target.
// We might nullify the _targetFront unexpectely due to previous target
// being destroyed after the new is created
if (this._targetFront) {
this._targetFront.off("target-destroyed", this._onTargetDestroyed);
}
this._targetFront = newTargetFront;
this._targetFrontPromise = null;
return targetFront;
return newTargetFront;
})();
return this._targetFrontPromise;
}

Просмотреть файл

@ -542,17 +542,21 @@ class TargetCommand extends EventEmitter {
* The BrowsingContextTargetFront instance that navigated to another process
*/
async onLocalTabRemotenessChange(targetFront) {
// By default, we do close the DevToolsClient when the target is destroyed.
// This happens when we close the toolbox (Toolbox.destroy calls Target.destroy),
// or when the tab is closes, the server emits tabDetached and the target
// destroy itself.
// Here, in the context of the process switch, the current target will be destroyed
// due to a tabDetached event and a we will create a new one. But we want to reuse
// the same client.
targetFront.shouldCloseClient = false;
// TabDescriptor may emit the event with a null targetFront, interpret that as if the previous target
// has already been destroyed
if (targetFront) {
// By default, we do close the DevToolsClient when the target is destroyed.
// This happens when we close the toolbox (Toolbox.destroy calls Target.destroy),
// or when the tab is closes, the server emits tabDetached and the target
// destroy itself.
// Here, in the context of the process switch, the current target will be destroyed
// due to a tabDetached event and a we will create a new one. But we want to reuse
// the same client.
targetFront.shouldCloseClient = false;
// Wait for the target to be destroyed so that TabDescriptorFactory clears its memoized target for this tab
await targetFront.once("target-destroyed");
// Wait for the target to be destroyed so that TabDescriptorFactory clears its memoized target for this tab
await targetFront.once("target-destroyed");
}
// Fetch the new target from the descriptor.
const newTarget = await this.descriptorFront.getTarget();