From bfe74d38d6ff87f2b0727eda708c31270248d349 Mon Sep 17 00:00:00 2001 From: kran6a Date: Wed, 8 Jan 2025 10:22:56 +0000 Subject: [PATCH 1/2] feat: support sveltekit apps on non-http protocols --- packages/kit/src/runtime/client/utils.js | 5 +++++ packages/kit/src/runtime/server/page/render.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/kit/src/runtime/client/utils.js b/packages/kit/src/runtime/client/utils.js index 2a0c35f344e9..0eb5d86b0eec 100644 --- a/packages/kit/src/runtime/client/utils.js +++ b/packages/kit/src/runtime/client/utils.js @@ -315,6 +315,11 @@ export function is_external_url(url, base, hash_routing) { return false; } + // be lenient if serving from an iframe via srcdoc + if (url.protocol === 'about:') { + return false; + } + // be lenient if serving from filesystem if (url.protocol === 'file:' && url.pathname.replace(/\/[^/]+\.html?$/, '') === base) { return false; diff --git a/packages/kit/src/runtime/server/page/render.js b/packages/kit/src/runtime/server/page/render.js index d8fbe32a7ed8..8451f0b8f45d 100644 --- a/packages/kit/src/runtime/server/page/render.js +++ b/packages/kit/src/runtime/server/page/render.js @@ -109,7 +109,8 @@ export async function render_response({ } } else if (options.hash_routing) { // we have to assume that we're in the right place - base_expression = "new URL('.', location).pathname.slice(0, -1)"; + // if we are not on an http protocol (eg: about: protocol on iframes) we default to an empty string. Otherwise an error would be thrown by the URL constructor + base_expression = `location.protocol.slice(0, 4) === "http" ? new URL(${s(base)}, location).pathname.slice(0, -1) : ""`; } } From 878c2d3dade2a089c3ba357125e9c0a00daca807 Mon Sep 17 00:00:00 2001 From: kran6a Date: Wed, 8 Jan 2025 10:22:56 +0000 Subject: [PATCH 2/2] feat: support sveltekit apps on non-http protocols --- .changeset/dirty-impalas-glow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dirty-impalas-glow.md diff --git a/.changeset/dirty-impalas-glow.md b/.changeset/dirty-impalas-glow.md new file mode 100644 index 000000000000..fe3b54d68134 --- /dev/null +++ b/.changeset/dirty-impalas-glow.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Added support for loading sveltekit apps on non-http protocols (eg: the `about:` protocol used on iframes that are populated via srcdoc)