Issue:
Window.screenX & screenY not producing correct location in KM10
For those users whose script in Custom HTML Prompt Action is using window.screenX & screenY api to save the location of window and to be restored later, take note that the API that works previously in KM9 no longer work correctly in KM10. It will return the wrong value ( eg 0 for x, wrong value for Y)
Solution:
This WKWebview issue (which KM10 is using to replace the old webview) is confirmed by Peter who suggest the fix is to use WINDOW(Left) for X and WINDOW(Top) for Y in KM10 . The window function is found in [function:WINDOW [Keyboard Maestro Wiki]].
However I have put forth a seamless fix that just need to be added to any script that use screenX and screenY. You can test it by running the attached javascript file in Custom HTML Prompt action.
(Probably this fix should be added into KM engine by Peter so users don't have to be manually add to their script ? ) - Have confirmed with Peter that he prefer to wait for Apple to fix this WKWebview issue, so the meantime, if anyone that want to fix the issue in their script easily, they can just add that fix at the top of script.
The fix is adding the following at the top of the script to override the screenX and screenY read accessor.
(function fixWindowScreenLocIssue() {
Object.defineProperty(window, "screenX", {
get: function () {
return parseInt(window.KeyboardMaestro?.Calculate("WINDOW(Left)")
?? window.screenX);
}
});
Object.defineProperty(window, "screenY", {
get: function () {
return parseInt(window.KeyboardMaestro?.Calculate("WINDOW(Top)")
?? window.screenY);
}
});
})();
To test the effect of script , just toggle the variable "useFix" , as the window move, the location info will be updated.
get_window_location.html.zip (1.2 KB)
[Script Modification History: 10 Nov 2021 12:53 pm US time] – Add parseInt to read accessor as window.KeyboardMaestro?.Calculate function return string. Actual result should be number type not string.