Forum Discussion

HirendraSingh's avatar
HirendraSingh
Contributor
21 days ago

Normal Edge launch along with Private Edge mode. (Random issue)

I am facing a random issue as I want to launch Edge in Private window then start execution in same.
Sometimes it is working fine but sometime I launches Edge in Private along with with Edge in normal mode, due to this my script fails.
Using below script then calling same in Keyword test.

function LaunchEdgeInPrivate() {
    // Path to the Edge executable
    const edgePath = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";  // Ensure this path is correct
    
    // Command line argument to open in InPrivate mode
    const edgeOptions = '--inprivate';
    
    // Full command to execute
    const command = `"${edgePath}" ${edgeOptions}`;
    
    // Create a WSH Shell object to run the command
    var wshShell = Sys.OleObject("WScript.Shell");
    
    // Run the command (0 = run in background, 1 = activate window)
    wshShell.Run(command, 1, false);  // false to not wait for completion
}

Keyword test:

 

3 Replies

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    Either of these three options will work,

    function launch()
    {
        let path = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
        let option =  "-inprivate";
        let command = `"${path}" ${option}`;
        Log.Message(`Command is '${command}'`);
        
        WshShell.Run(command);
        
        getActiveXObject("WScript.Shell").Run(command);
    
        Sys.OleObject("WScript.Shell").Run(command);
    }

    Note, the Run method has no parameters. You also need to ensure your Edge is configured correctly, as it can run in the background.

    • HirendraSingh's avatar
      HirendraSingh
      Contributor

      I had tried this code but its opening 3 private window in single time.

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        If you are running the three (option) lines of code i.e.

        WshShell.Run(command);
            
        getActiveXObject("WScript.Shell").Run(command);
        
        Sys.OleObject("WScript.Shell").Run(command)

        Then it will open the browser three times! Choose one that suits your needs.