Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/playwright-core/src/server/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export type BrowserOptions = {
userDataDir?: string;
noDefaults?: boolean;
isWebView?: boolean;
// Do not send Inspector.enable to detect pages without a renderer while connecting.
noInspectorEnableOnConnect?: boolean;
};

export abstract class Browser extends SdkObject {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ class FrameSession {
for (const initScript of this._crPage._page.allInitScripts())
promises.push(this._evaluateOnNewDocument(initScript, 'main', true /* runImmediately */));
}
if (this._isMainFrame() && this._crPage._browserContext._browser._isConnecting) {
if (this._isMainFrame() && this._crPage._browserContext._browser._isConnecting && !browserOptions.noInspectorEnableOnConnect) {
// An existing page without a renderer, e.g. crashed or discarded, never responds to the commands above.
// Get notified with Inspector.targetCrashed right away, so that such a page is reported as closed,
// and we do not stall while connecting to the browser.
Expand Down
2 changes: 2 additions & 0 deletions packages/playwright-core/src/server/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ export class Electron extends SdkObject {
downloadsPath: artifactsDir,
tracesDir: options.tracesDir || artifactsDir,
originalLaunchOptions: {},
// A window that has not navigated yet has no renderer, but it is not crashed.
noInspectorEnableOnConnect: true,
};
validateBrowserContextOptions(contextOptions, browserOptions);
const browser = await progress.race(CRBrowser.connect(this.attribution.playwright, chromeTransport, browserOptions));
Expand Down
10 changes: 10 additions & 0 deletions tests/electron/electron-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ test('should be able to get the first window when with a delayed navigation', as
await expect(page.locator('h1')).toHaveText('Foobar');
});

test('should be able to get the first window with a delayed navigation when launched via executablePath', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43247' },
}, async ({ launchElectronApp }) => {
// Like a packaged app: without our loader, the window is created while Playwright is still connecting.
const app = await launchElectronApp('electron-window-app-delayed-loadURL.js', [], { executablePath: require('electron/index.js') });
const page = await app.firstWindow();
await expect(page).toHaveURL('data:text/html,<h1>Foobar</h1>');
await expect(page.locator('h1')).toHaveText('Foobar');
});

test('should detach debugger on app-initiated exit', async ({ launchElectronApp }) => {
const electronApp = await launchElectronApp('electron-app.js');
const closePromise = new Promise(f => electronApp.process().on('close', f));
Expand Down
Loading