%FrontBrowserURL% do not return URL when Safari is getting a 404

Hi !

First time posting here :grin:

Description

At work, we have application that send email notification. When working remotely, the URLs in those mail do not work because of network-proxy-shenanigan.

I'm trying to set a macro that transform the clicked links so the app can be accessed. It works fine with Chrome but don't with Safari.

The problems is that %FrontBrowserURL% returns safari-resource:/ErrorPage.html when hitting a 404 instead of the actual URL.

I tried to get the URL via Apple Script but it returns the same value

tell application "Safari"
	return URL of front document as string
end tell

and Javascript where I get nothing

function run(input, parameters) {

    var app = Application("Safari");
    app.includeStandardAdditions = true;

    var url = app.doJavaScript('window.getSelection().anchorNode.parentNode.href',{
        in: app.windows[0].currentTab
    });

    return url;
}

Ask

Did someone know how to get the actual URL in Safari even if accessing an inaccessible page (404, etc) ?

Additional info

Here's is my macro
Convert links.kmmacros (9.6 KB)

Not a full URL, but the "not found" page does include server and path. So this might be enough for now:

Safari -- Get URL of 404.kmmacros (2.4 KB)

Image

1 Like

@Nige_S Thanks for the help.

Here's how I have done that:
CleanShot 2023-01-26 at 14.50.33

Do you have a working example of a 404 error handy?