Skip to content

[BUG] electron.app.getAppPath() returns the path one level higher if you run electron pointing to the directory #19540

Closed

Description

Context:

  • Playwright Version:1.29.0
  • Operating System: Windows
  • Node.js version: v18.9.0
  • Browser: Electron
  • Extra: [any specific details about your environment]

System:

  • OS: Windows 10 10.0.19045
  • Memory: 5.37 GB / 15.42 GB

Binaries:

  • Node: 18.9.0 - C:\Program Files\nodejs\node.EXE
  • Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
  • npm: 8.19.1 - C:\Program Files\nodejs\npm.CMD

Languages:

  • Bash: 5.2.12 - C:\Program Files\Git\usr\bin\bash.EXE

npmPackages:

  • playwright: 1.29.0 => 1.29.0

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally. For example:

import {_electron as electron} from 'playwright';

let electronApp = await electron.launch({args: [process.cwd()]});

const appPath = await electronApp.evaluate(async ({app}) => app.getAppPath());
console.assert(
    appPath === process.cwd(),
    `appPath expect value: ${process.cwd()}, but got ${appPath}`
)

await electronApp.close()

Describe the bug
Calling app.getAppPath() return wrong path in playwrite context. Here is repo with reproduction: https://github.com/cawa-93/issue-playwrite-electron-getAppPath

  1. Clone and install dependencies npm ci
  2. Run node e2e.spec.mjs
$ node ./e2e.spec.mjs
{
  'app.getAppPath()': 'C:\\Users\\kozac\\Dev\\temp-projects',
  cwd: 'C:\\Users\\kozac\\Dev\\temp-projects\\issue-playwrite-electron-getAppPath'
}
Assertion failed

On my machine the app.getAppPath() function is expected to return C:\Users\kozac\Dev\temp-projects\issue-playwrite-electron-getAppPath but it always return a one level highter: C:\Users\kozac\Dev\temp-projects

You can also run same in pure electron context by electron .

$ electron .

{
  'app.getAppPath()': 'C:\\Users\\kozac\\Dev\\temp-projects\\issue-playwrite-electron-getAppPath',
  cwd: 'C:\\Users\\kozac\\Dev\\temp-projects\\issue-playwrite-electron-getAppPath'
}

This is reproduced by setting the absolute or relative path to the directory in which the manifest resides.

electron.launch({args: [process.cwd()]});
// or
electron.launch({args: ['.']});

If you set the path directly to the index file, then everything works as expected

electron.launch({args: ['./index.cjs']});
$ node ./e2e.spec.mjs
{
  'app.getAppPath()': 'C:\\Users\\kozac\\Dev\\temp-projects\\issue-playwrite-electron-getAppPath',
  cwd: 'C:\\Users\\kozac\\Dev\\temp-projects\\issue-playwrite-electron-getAppPath'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions