diff --git a/packages/playwright-core/src/server/electron/electron.ts b/packages/playwright-core/src/server/electron/electron.ts index 7ad3995494..384f346111 100644 --- a/packages/playwright-core/src/server/electron/electron.ts +++ b/packages/playwright-core/src/server/electron/electron.ts @@ -130,7 +130,7 @@ export class Electron extends SdkObject { controller.setLogName('browser'); return controller.run(async progress => { let app: ElectronApplication | undefined = undefined; - const electronArguments = ['-r', require.resolve('./loader'), '--inspect=0', '--remote-debugging-port=0', ...args]; + const electronArguments = ['--inspect=0', '--remote-debugging-port=0', ...args]; if (os.platform() === 'linux') { const runningAsRoot = process.geteuid && process.geteuid() === 0; @@ -160,6 +160,9 @@ export class Electron extends SdkObject { } throw error; } + // Only use our own loader for non-packaged apps. + // Packaged apps might have their own command line handling. + electronArguments.unshift('-r', require.resolve('./loader')); } // When debugging Playwright test that runs Electron, NODE_OPTIONS diff --git a/tests/electron/electron-app.spec.ts b/tests/electron/electron-app.spec.ts index c221d51db4..ee54cf2e2a 100644 --- a/tests/electron/electron-app.spec.ts +++ b/tests/electron/electron-app.spec.ts @@ -49,10 +49,10 @@ test('should script application', async ({ electronApp }) => { }); test('should preserve args', async ({ launchElectronApp, isMac }) => { - test.fixme(isMac, 'https://github.com/microsoft/playwright/issues/21512'); const electronApp = await launchElectronApp('electron-app-args.js', ['foo', 'bar']); const argv = await electronApp.evaluate(async () => globalThis.argv); - expect(argv).toEqual([expect.stringContaining(path.join('dist', 'electron')), expect.stringContaining(path.join('electron', 'electron-app-args.js')), 'foo', 'bar']); + const electronPath = isMac ? path.join('dist', 'Electron.app') : path.join('dist', 'electron'); + expect(argv).toEqual([expect.stringContaining(electronPath), expect.stringContaining(path.join('electron', 'electron-app-args.js')), 'foo', 'bar']); }); test('should return windows', async ({ electronApp, newWindow }) => { diff --git a/tests/electron/electronTest.ts b/tests/electron/electronTest.ts index 05361a20ff..68261cfa16 100644 --- a/tests/electron/electronTest.ts +++ b/tests/electron/electronTest.ts @@ -16,7 +16,7 @@ import { baseTest } from '../config/baseTest'; import * as path from 'path'; -import type { ElectronApplication, Page } from '@playwright/test'; +import type { ElectronApplication, Page, Electron } from '@playwright/test'; import type { PageTestFixtures, PageWorkerFixtures } from '../page/pageTestApi'; import type { TraceViewerFixtures } from '../config/traceViewerFixtures'; import { traceViewerFixtures } from '../config/traceViewerFixtures'; @@ -26,7 +26,7 @@ import { assert } from '../../packages/playwright-core/lib/utils/debug'; type ElectronTestFixtures = PageTestFixtures & { electronApp: ElectronApplication; - launchElectronApp: (appFile: string, args?: string[], options?: any) => Promise; + launchElectronApp: (appFile: string, args?: string[], options?: Parameters[0]) => Promise; newWindow: () => Promise; }; @@ -45,7 +45,7 @@ export const electronTest = baseTest.extend(traceViewerFixt // This env prevents 'Electron Security Policy' console message. process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'; const apps: ElectronApplication[] = []; - await use(async (appFile: string, args: string[] = [], options?: any[]) => { + await use(async (appFile: string, args: string[] = [], options?: Parameters[0]) => { const app = await playwright._electron.launch({ ...options, args: [path.join(__dirname, appFile), ...args] }); apps.push(app); return app;