Skip to content

Commit 78b93aa

Browse files
authored
tests(devtools): ensure device emulation is ready (#14431)
1 parent b61e8c3 commit 78b93aa

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

core/scripts/pptr-run-devtools.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ function addSniffer(receiver, methodName, override) {
145145
}
146146

147147
async function waitForLighthouseReady() {
148+
// Undocking later in the function can cause hiccups when Lighthouse enables device emulation.
149+
// @ts-expect-error global
150+
UI.dockController.setDockSide('undocked');
151+
148152
// @ts-expect-error global
149153
const viewManager = UI.viewManager || (UI.ViewManager.ViewManager || UI.ViewManager).instance();
150154
const views = viewManager.views || viewManager._views;
@@ -156,9 +160,6 @@ async function waitForLighthouseReady() {
156160
const button = panel.contentElement.querySelector('button');
157161
if (button.disabled) throw new Error('Start button disabled');
158162

159-
// @ts-expect-error global
160-
UI.dockController.setDockSide('undocked');
161-
162163
// Give the main target model a moment to be available.
163164
// Otherwise, 'SDK.TargetManager.TargetManager.instance().mainTarget()' is null.
164165
// @ts-expect-error global
@@ -183,6 +184,13 @@ async function waitForLighthouseReady() {
183184
}
184185
}
185186
}
187+
188+
// Ensure the emulation model is ready before Lighthouse starts by enabling device emulation.
189+
// @ts-expect-error global
190+
const {deviceModeView} = Emulation.AdvancedApp.instance();
191+
if (!deviceModeView.isDeviceModeOn()) {
192+
deviceModeView.toggleDeviceMode();
193+
}
186194
}
187195

188196
async function runLighthouse() {

0 commit comments

Comments
 (0)