StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Gilers  
#1 Posted : Monday, December 26, 2022 4:29:22 PM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

I set up a loop that opens multiple browsers at once. Can anyone tell me how to save the opened browsers into an array for later access?


for (var i = 0; i < chrzh.length; i++) {
sp.RunProgram('Chrome', chrzh[i],'open', 'normal', true, false, false);
sp.Sleep(100);
//save chrome window to array?
sp.Sleep(500);
}


Rob  
#2 Posted : Tuesday, December 27, 2022 3:12:33 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This works in theory, but if Chrome is already running and just creating a new window under an existing process, it exits right away and the proc.MainWindowHandle variable is not valid.

If your chrzh array has arguments that are creating fully new processes of Chrome, it should work fine.

Code:
// Create or clear list for storing Chrome window handles
if(sp.GetStoredObject("ChromeHandles").GetType().FullName == "System.Object") {
    sp.StoreObject("ChromeHandles", new List(System.IntPtr));
} else {
    sp.GetStoredObject("ChromeHandles").Clear();
}

for (var i = 0; i < chrzh.length; i++) {

    var start = new System.Diagnostics.ProcessStartInfo();
    start.FileName = "chrome";
    start.Arguments = chrzh[i];
    start.Verb = "open";
    start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; 
    start.UseShellExecute = true;
    start.CreateNoWindow = false;

    // Start process 
    var proc = System.Diagnostics.Process.Start(start);

    // Wait 250ms for window to open - may need to increase
    sp.Sleep(250);

    // Save main window handle to list
    sp.GetStoredObject("ChromeHandles").Add(proc.MainWindowHandle);

    sp.Sleep(500);
}

// Loop through and display the stored Chrome window handles 
for(var i = 0; i < sp.GetStoredObject("ChromeHandles").Count; i++) {
    sp.MessageBox(sp.GetStoredObject("ChromeHandles")[i].ToString(), `Chrome Window ${i}`);
}
Gilers  
#3 Posted : Tuesday, December 27, 2022 5:47:37 PM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

Thanks for your reply, Rob
I haven't had time to test yet
I would like to add that the above chrmzh array contains chrome account tags, such as --profile-directory="Profile 28", --profile-directory="Profile 32" to specify the account I want to open.
Will this parameter affect the above script?
Gilers  
#4 Posted : Tuesday, December 27, 2022 6:12:06 PM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

UserPostedImage

My array of "chrzh", listed below

var chrzh = [String.raw`--profile-directory="Profile 28"` ,
String.raw`--profile-directory="Profile 51"`,
String.raw`--profile-directory="Profile 30"`,
String.raw`--profile-directory="Profile 45"`,
String.raw`--profile-directory="Profile 20"`,
String.raw`--profile-directory="Profile 3"`,
String.raw`--profile-directory="Profile 52"`,
String.raw`--profile-directory="Profile 9"`,
String.raw`--profile-directory="Profile 2"`,
];


Then add your script and run it, an error occurs, do you know what went wrong?
I have opened some chrome windows when running the script.

UserPostedImage
Gilers  
#5 Posted : Wednesday, December 28, 2022 3:10:21 PM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

I need to do some repeated operations on these open windows, and I need to use another gesture to continue to operate on these windows. I would like to ask, after opening, can I still operate them in the order they were opened? Even though there were out-of-order window switching between the two gestures.
Hope you can help me to solve this problem, it will save me a lot of time.
Thanks in advance!
Gilers  
#6 Posted : Wednesday, December 28, 2022 3:51:51 PM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

Can you save the window handles to an external file according to the opening order when opening all windows, and then read the order from the external file next time.
I just have this idea, but don't know how to implement it.
Rob  
#7 Posted : Wednesday, December 28, 2022 6:04:37 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Honestly, it can be tricky since chrome.exe just sends a message to the main Chrome process and exits. You would have to rely on waiting for the window to show up and hopefully get/store the handle to it.

The most stable approach would be to use the S+ HTMLWindow, as you can name and know exactly each web window. This uses Microsoft's WebView2 component (which is Edge/Chromium).

In S+ version 0.5.7.1, I added the ability to specify a profile name, so each HTMLWindow instance can have its own cookies, etc.

See this script for examples:
Code:
function webViewWindowCallback(e) {
    let obj = JSON.parse(e);

    // This is being sent by S+ on init
    if (obj.StrokesPlusHTMLWindow) {

        // Create WebView2 window ID/handles collection if it doesn't exist
        if(sp.GetStoredObject("WebViewHandles").GetType().FullName == "System.Object") {
            sp.StoreObject("WebViewHandles", new List(System.Tuple(System.String, System.IntPtr)));
        }

        // Store window ID/handle and maximize
        var handle = new IntPtr(parseInt(obj.StrokesPlusHTMLWindow.Handle))
        sp.GetStoredObject("WebViewHandles").Add(new System.Tuple(System.String, System.IntPtr, obj.StrokesPlusHTMLWindow.ID, handle));
        sp.WindowFromHandle(handle).Maximize();

        //Clean up any invalid window handles (closed windows, for example)
        var validHandles = new List(System.Tuple(System.String, System.IntPtr));
        for(var w = 0; w < sp.GetStoredObject("WebViewHandles").Count; w++) {
            if(sp.WindowFromHandle(sp.GetStoredObject("WebViewHandles")[w].Item2).IsValid()) {
                validHandles.Add(new System.Tuple(System.String, System.IntPtr, sp.GetStoredObject("WebViewHandles")[w].Item1, sp.GetStoredObject("WebViewHandles")[w].Item2));
            }
        }
        sp.StoreObject("WebViewHandles", validHandles);
    } 
}

sp.HTMLWindow("Profile 1", "https://exmark.com", "webViewWindowCallback", "", "ID1", false, false, "Profile 1", "");
sp.HTMLWindow("Profile 2", "https://exmark.com", "webViewWindowCallback", "", "ID2", false, false, "Profile 2", "");
sp.HTMLWindow("Profile 3", "https://exmark.com", "webViewWindowCallback", "", "ID3", false, false, "Profile 3", "");

/*

// See count of window handles
StrokesPlus.Console.Log(sp.GetStoredObject("WebViewHandles").Count);

// Specifically reference a window by index
sp.WindowFromHandle(sp.GetStoredObject("WebViewHandles")[0].Item2).Activate();
sp.WindowFromHandle(sp.GetStoredObject("WebViewHandles")[1].Item2).Activate();

// Find a window by ID
for(var w = 0; w < sp.GetStoredObject("WebViewHandles").Count; w++) {
    if(sp.GetStoredObject("WebViewHandles")[w].Item1 === "ID2") {
        sp.WindowFromHandle(sp.GetStoredObject("WebViewHandles")[w].Item2).Activate();
    }
}

*/

Edited by user Wednesday, December 28, 2022 6:06:07 PM(UTC)  | Reason: Not specified

Gilers  
#8 Posted : Thursday, December 29, 2022 4:56:33 PM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

Thank you Rob, I updated to the latest version, tested your code and saw the effect, it is really cool. But there is a problem. My information in the Google user account is gone. He is not a user who opened Google, but a new user. This problem is not what I want to see. Still thank you for your efforts.
Another way of thinking, can I create an empty array to hold these open windows so that I can use them in an orderly manner. If I use it next time, I also put them into the array. But I don't know how to create such an array.
Rob  
#9 Posted : Thursday, December 29, 2022 7:24:41 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Quote:
My information in the Google user account is gone.

Right, you would need to login to each of these profiles, then they will be remembered next time, as long as you use the same profile name again.

Think of each of these windows/profiles as separate incognito windows, so you need to get the logins, cookies, etc. setup the first time for each profile.

You could change the URL to google, sign in, then next time you run the profile, use a different URL and it would remember the google login from before.
Gilers  
#10 Posted : Saturday, December 31, 2022 4:51:38 PM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

Hi, Rob!
Can this S+ HTMLWindow use Chrome plugins? How do I Install the plug-ins in my original user to this page?
Rob  
#11 Posted : Sunday, January 1, 2023 6:49:43 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
https://github.com/Micro...bView2Feedback/issues/98

Looks like there is an open request for Microsoft to allow extensions for WebView2 (which is what S+ is using).

So until they add this functionality, S+ can't support it.

I will keep an eye on it and update S+ to the latest WebView2 when it's available.
Gilers  
#12 Posted : Monday, January 2, 2023 10:42:57 AM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

Thank you Rob, I will wait for your update!
Gilers  
#13 Posted : Wednesday, January 18, 2023 3:39:55 PM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

Hi rob!
Can I interact with pages using S+ HTMLWindow? For example, I want to get the text, pictures, or click buttons on the page.
sery111  
#14 Posted : Wednesday, April 26, 2023 9:15:57 AM(UTC)
sery111

Rank: Newbie

Reputation:

Groups: Approved
Joined: 12/29/2021(UTC)
Posts: 9

Thank you Rob.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.