diff --git a/src/extensionsIntegrated/Phoenix/new-project.js b/src/extensionsIntegrated/Phoenix/new-project.js index 09a126a342..b1641fcb37 100644 --- a/src/extensionsIntegrated/Phoenix/new-project.js +++ b/src/extensionsIntegrated/Phoenix/new-project.js @@ -55,6 +55,24 @@ define(function (require, exports, module) { createProjectDialogueObj, downloadCancelled = false; + function _focusContentWindow() { + let attempts = 0; + const maxAttempts = 10; // 10 * 100ms = 1 second total scan time + const intervalId = setInterval(() => { + const frame = document.getElementById("newProjectFrame"); + if (frame && frame.contentWindow) { + frame.contentWindow.focus(); + clearInterval(intervalId); + } + + attempts++; + if (attempts >= maxAttempts) { + clearInterval(intervalId); + console.warn("Could not find or focus on newProjectFrame"); + } + }, 100); + } + function _showNewProjectDialogue() { if(window.testEnvironment){ return; @@ -68,9 +86,7 @@ define(function (require, exports, module) { }; let dialogueContents = Mustache.render(newProjectTemplate, templateVars); newProjectDialogueObj = Dialogs.showModalDialogUsingTemplate(dialogueContents, true); - setTimeout(()=>{ - document.getElementById("newProjectFrame").contentWindow.focus(); - }, 100); + _focusContentWindow(); Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "dialogue", "open"); } diff --git a/src/file/FileUtils.js b/src/file/FileUtils.js index e878e97f8a..29220ebd36 100644 --- a/src/file/FileUtils.js +++ b/src/file/FileUtils.js @@ -422,6 +422,10 @@ define(function (require, exports, module) { * @return {string} Path of containing folder (including trailing "/"); or "" if path was the root */ function getParentPath(fullPath) { + // Guard clause: ensure fullPath is a non-empty string + if (typeof fullPath !== "string" || !fullPath) { + return ""; + } if (fullPath === "/") { return ""; }