Skip to content

Commit 17069e7

Browse files
authored
fix: Pick a default Edge binary location on all platforms (#65)
Since v120 or v121, msedgedriver always fails if you do not specify the Edge binary path. By assuming some platform-specific defaults, we can fix local testing on Edge in most cases.
1 parent f5442d4 commit 17069e7

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,30 @@ const LocalWebDriverChromeHeadless = generateSubclass(
300300
// that explicitly. This works around the following edgedriver bug:
301301
// https://github.com/MicrosoftEdge/EdgeWebDriver/issues/102#issuecomment-1710724173
302302
const edgeOptions = {};
303-
const edgeBinary = which.sync('microsoft-edge', {nothrow: true});
303+
let edgeBinary = which.sync('microsoft-edge', {nothrow: true});
304+
305+
if (!edgeBinary) {
306+
// Since v120 or v121, msedgedriver always fails if you do not specify the
307+
// Edge binary path. Assume some platform-specific defaults. Only use these
308+
// paths if they exist.
309+
switch (os.platform()) {
310+
case 'darwin':
311+
edgeBinary = '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge';
312+
break;
313+
case 'win32':
314+
edgeBinary = 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe';
315+
break;
316+
case 'linux':
317+
edgeBinary = '/opt/microsoft/msedge/microsoft-edge';
318+
break;
319+
}
320+
321+
// If that platform-specific binary doesn't exist, don't try to use it.
322+
if (edgeBinary && !fs.existsSync(edgeBinary)) {
323+
edgeBinary = null;
324+
}
325+
}
326+
304327
if (edgeBinary) {
305328
edgeOptions['ms:edgeOptions'] = {
306329
binary: edgeBinary,

0 commit comments

Comments
 (0)