From 05dc8e0627e1ff356485eafe0724db99cd2276a2 Mon Sep 17 00:00:00 2001
From: Simon Jockers <449739+sjockers@users.noreply.github.com>
Date: Mon, 23 Feb 2026 18:32:07 +0100
Subject: [PATCH 1/7] Log debug information
---
.../datawrapper-switcher/DatawrapperSwitcher.svelte | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
index 0732296f..34c6b8a0 100644
--- a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
+++ b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
@@ -21,7 +21,10 @@
- Datawrapper switcher to be rendered here:
+ {JSON.stringify({ labels, ids, fixedHeight, layout }, null, 2)}
+
+
-
+
From 7eba3c0f831d7a35720826c0d6909d5fe8dc9699 Mon Sep 17 00:00:00 2001
From: Simon Jockers <449739+sjockers@users.noreply.github.com>
Date: Wed, 25 Feb 2026 11:10:29 +0100
Subject: [PATCH 2/7] Refactor getDataFromUrl (less specific to domains, add
error logging)
---
.../src/lib/utils/getDataFromUrl.ts | 29 ++++++++-----------
.../DatawrapperSwitcher.svelte | 6 ++++
2 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/sophora-components/src/lib/utils/getDataFromUrl.ts b/sophora-components/src/lib/utils/getDataFromUrl.ts
index 9448278c..ac1fe0fa 100644
--- a/sophora-components/src/lib/utils/getDataFromUrl.ts
+++ b/sophora-components/src/lib/utils/getDataFromUrl.ts
@@ -1,21 +1,16 @@
export default function getDataFromUrl(target: HTMLElement): Record {
- let url: URL;
- if (
- // SvelteKit DEV mode, preview server, or static hosting:
- import.meta.env.DEV ||
- window.location.origin === 'http://localhost:4173' ||
- window.location.origin === 'https://static.datenhub.net' ||
- window.location.href.includes('apidata.googleusercontent.com') ||
- window.location.href.includes('storage.googleapis.com')
- ) {
+ const parent = target.parentNode?.parentNode as HTMLElement | null;
+
+ // Default: Embedded mode – use URL used to embed the component
+ // `data-url` is the embeds the grandparent element, provided by Sophora
+ let embedURL = parent?.dataset.url;
+
+ if (!embedURL) {
// Preview mode – use URL of current page
- url = new URL(window.location.href);
- } else {
- // Embedded mode – use URL used to embed the component
- // `data-url` is set on the grandparent element, provided by Sophora
- const parent = target.parentNode?.parentNode as HTMLElement | null;
- url = new URL(parent?.dataset.url || '');
+ embedURL = window?.location.href;
}
- const params: Record = Object.fromEntries(url.searchParams);
- return params;
+
+ return URL.canParse(embedURL)
+ ? Object.fromEntries(new URL(embedURL).searchParams.entries())
+ : (console.error('Could not parse Embed-URL:', embedURL), {});
}
diff --git a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
index 34c6b8a0..10d27c1f 100644
--- a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
+++ b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
@@ -10,12 +10,16 @@
let fixedHeight = $state(null);
let layout = $state('auto');
+ let url = $state('');
+
onMount(() => {
const entries = getDataFromUrl(root);
labels = entries.labels.split(',') || [];
ids = entries.ids.split(',') || [];
fixedHeight = entries.fixedHeight || null;
layout = entries.layout || 'auto';
+
+ url = window.location?.href;
});
@@ -23,6 +27,8 @@
Datawrapper switcher to be rendered here:
{JSON.stringify({ labels, ids, fixedHeight, layout }, null, 2)}
+ dataset url: {root?.parentNode?.parentNode?.dataset.url || 'n/a'}
+ actual url: {url || 'n/a'}
+ />
-
+
+
+ Debug Information:
+ data-url: {root?.parentNode?.parentNode?.dataset.url || 'n/a'}
+
+ {JSON.stringify({ labels, ids, fixedHeight, layout }, null, 2)}
+ {#if error}
+ {error}
+ {/if}
From ed23bc7da5ce6f5cabcabaad661a756ae84efa8c Mon Sep 17 00:00:00 2001
From: Simon Jockers <449739+sjockers@users.noreply.github.com>
Date: Thu, 26 Feb 2026 20:39:53 +0100
Subject: [PATCH 7/7] Show actual page URL in debugging
---
.../src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
index 1a0a9d8d..85dcc32c 100644
--- a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
+++ b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte
@@ -14,6 +14,8 @@
let error = $state(null);
onMount(() => {
+ url = window?.location.href;
+
try {
const entries = getDataFromUrl(root);
labels = entries.labels?.split(',') || [];
@@ -57,6 +59,7 @@
Debug Information:
+ actual url: {url || 'n/a'}
data-url: {root?.parentNode?.parentNode?.dataset.url || 'n/a'}
{JSON.stringify({ labels, ids, fixedHeight, layout }, null, 2)}