javascriptyahooyahoo-mail

How to register Yahoo Mail `mailto` protocol handler in Chrome?


how can i register the mailto: protocol handler for the Yahoo Mail web client?

I know the javascript to run should be smt like this:

navigator.registerProtocolHandler('mailto', 'https://compose.mail.yahoo.com/?%s', 'Yahoo Mail');

The problem is, their email composition URL domain compose.mail.yahoo.com is not the same as their main one mail.yahoo.com, so running registerProtocolHandler in the mail.yahoo.com inspector console gives the error:

Uncaught DOMException: Failed to execute 'registerProtocolHandler' on 'Navigator': Can only register custom handler in the document's origin. at :1:11

... and you can't run it in a compose.mail.yahoo.com window because it immediately redirects away with an HTTP 302 to login.yahoo.com with an additional redirect (if you're logged in) to mail.yahoo.com/d/compose.


So i can register such an handler? I just need to find a way to execute that javascript in the context of compose.mail.yahoo.com, i think..


Solution

  • Another possibility would be to setup a little redirect page on a website you possess, with a simple script like:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
    </head>
    
    <body>
        <script>
            const urlParams = new URLSearchParams(window.location.search)
            if (urlParams.has('s')) {
                // if parameter "s" present, create URL and navigate
                const s = urlParams.get('s')
                document.location.href = `https://compose.mail.yahoo.com/?to=${encodeURIComponent(s)}`
            } else {
                // else, allow the user to register the handler
                function register() {
                    const newHandler = `https://${document.location.host + document.location.pathname}?s=%s`
                    navigator.registerProtocolHandler('mailto', newHandler)
                }
            }
        </script>
    
        <button onclick="register()">register protocol handler for mailto: links</button>
        <a target="_blank"
            href="mailto:someone@yoursite.com?cc=someoneelse@theirsite.com, another@thatsite.com, me@mysite.com&bcc=lastperson@theirsite.com&subject=Big%20News&body=Body+goes+here">Email
            test link</a>
    </body>
    
    </html>