Bug 1774476 - [cdp] Delay initialization of CDP until browserStartupFinished. r=webdriver-reviewers,jgraham

Initializing CDP before the first window has been opened can break
the registration of the first browser window because a pre-loaded
window gets opened first before the gBrowser is attached.

This also prevents any CDP client to connect to any the JSONHandler
end-points before CDP is actually ready.

Differential Revision: https://phabricator.services.mozilla.com/D151843
This commit is contained in:
Henrik Skupin 2022-07-15 06:30:34 +00:00
parent 86e5c90753
commit 1ed1175d97

View File

@ -86,6 +86,13 @@ class CDP {
lazy.RecommendedPreferences.applyPreferences(RECOMMENDED_PREFS);
// Starting CDP too early can cause issues with clients in not being able
// to find any available target. Also when closing the application while
// it's still starting up can cause shutdown hangs. As such CDP will be
// started when the initial application window has finished initializing.
lazy.logger.debug(`Waiting for initial application window`);
await this.agent.browserStartupFinished;
this.agent.server.registerPrefixHandler(
"/json/",
new lazy.JSONHandler(this)
@ -101,13 +108,6 @@ class CDP {
await this.targetList.watchForTargets();
// Starting CDP too early can cause issues with clients in not being able
// to find any available target. Also when closing the application while
// it's still starting up can cause shutdown hangs. As such CDP will be
// started when the initial application window has finished initializing.
lazy.logger.debug(`Waiting for initial application window`);
await this.agent.browserStartupFinished;
Cu.printStderr(`DevTools listening on ${this.address}\n`);
// Write connection details to DevToolsActivePort file within the profile.