'SvelteKit - get protocol

Is it possible in SvelteKit to get protocol of current page (HTTP or HTTPS)?

Something like:

import {page} from '$app/stores';

console.log($page.protocol);

So far, I only see:

{
  host: 'localhost:3000',
  path: '/projektDetalji',
  query: URLSearchParams { 'id' => '1' },
  params: {}
}


Solution 1:[1]

You could use browser to make sure you are running in browser, then grab protocol from window.location.protocol.

<script context="module">
  import { browser } from "$app/env"
  if (browser) {
    console.log(window.location.protocol);
  }
</script>

From $app/env module section of sveltekit docs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1