Workers Redirect to sms protocol causes Exception

Gist of the problem in the title; http, https, and ftp urls work:

redir = ‘https://google.com
const statusCode = 302;
return Response.redirect(redir,statusCode)

sms URLs do not:
redir = ‘sms:+18449203663’
const statusCode = 302;
return Response.redirect(redir,statusCode)

error message: “Unable to parse URL: sms:+18449203663”

We’ve tried sms://+1… (although that’s not the spec) — same result.

Is it possible to construct the raw pieces of a response, bypassing the URL parse?
Tks

Hi there,

Yes! All Response.redirect() does is set a status code, validate the URL and set the Location header. You can manually return a redirect like this:

return new Response(null, {
    status: 302,
    headers: {'Location': 'sms:+18449203663'}
})

The above code correctly prompts me to “Open Messages” when visiting on my phone :slightly_smiling_face:

Thank you, @albert !!
I -never- would have thought to manage that via headers — awesome.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.