Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,382 Location: Tampa, FL Thanks: 28 times Was thanked: 430 time(s) in 363 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
|