Orion Web Browser: Getting URL or Title via Applescript

PS as you know the difference between the WebKit and Chrome osascript interfaces turns on a single difference: currentTabactiveTab, so given a bundle id for the browser, we might write (in a JavaScript rather than AppleScript idiom of osascript), for example:

Expand disclosure triangle to view JS source
(() => {
    "use strict";

    // Rob Trew @2023

    const main = () =>
        either(x => x)(x => x)(
            browserLinkLR("com.kagi.kagimacOS")
        );

    // ------------------ BROWSER LINKS ------------------

    // browserLinkLR :: String -> Either String IO String
    const browserLinkLR = bundleID => {
        const w = Application(bundleID).windows.at(0);

        return w.exists()
            ? w.tabs.at(0).exists() ? (() => {
                const
                    tab = w[
                    [
                        "com.apple.Safari",
                        "com.kagi.kagimacOS"
                    ]
                    .includes(bundleID)
                        ? "currentTab"
                        : "activeTab"
                    ]();

                return Right(
                    `[${tab.name()}](${tab.url()})`
                );
            })() : Left(
                `No open tabs in front window of ${bundleID}`
            )
            : Left(`No windows open in ${bundleID}`);
    };

    // --------------------- GENERIC ---------------------

    // Left :: a -> Either a b
    const Left = x => ({
        type: "Either",
        Left: x
    });


    // Right :: b -> Either a b
    const Right = x => ({
        type: "Either",
        Right: x
    });


    // either :: (a -> c) -> (b -> c) -> Either a b -> c
    const either = fl =>
        // Application of the function fl to the
        // contents of any Left value in e, or
        // the application of fr to its Right value.
        fr => e => e.Left ? (
            fl(e.Left)
        ) : fr(e.Right);


    return main();
})();