From 0ee3b32ef341d190c014bc84c9b33c4f29c997f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Mon, 12 Jan 2026 15:34:43 +0100 Subject: [PATCH] Fix: Use data URL iframe with auto-submitting form for Collabora POST - Create iframe with data URL containing HTML page - HTML page has form that auto-submits to loleaflet.html with WOPISrc in body - This ensures POST request instead of GET - Form submits within iframe context, not affected by parent page JavaScript --- b0esche_cloud/lib/pages/document_viewer.dart | 71 +++++++++----------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/b0esche_cloud/lib/pages/document_viewer.dart b/b0esche_cloud/lib/pages/document_viewer.dart index ca877aa..6dc0a8a 100644 --- a/b0esche_cloud/lib/pages/document_viewer.dart +++ b/b0esche_cloud/lib/pages/document_viewer.dart @@ -450,21 +450,12 @@ class _DocumentViewerModalState extends State { Widget _buildCollaboraIframe(String wopisrc) { // For Collabora Online, we need to POST the WOPISrc, not GET it - // Use JavaScript to create and submit the form properly + // Create an HTML page with auto-submitting form and set as iframe src final String viewType = 'collabora-form-${DateTime.now().millisecondsSinceEpoch}'; ui.platformViewRegistry.registerViewFactory(viewType, (int viewId) { - // Create a container for the form and iframe - final container = html.DivElement() - ..style.width = '100%' - ..style.height = '100%' - ..style.margin = '0' - ..style.padding = '0' - ..style.overflow = 'hidden'; - - // Create the iframe first + // Create the iframe final iframe = html.IFrameElement() - ..name = 'collabora-iframe-$viewId' ..style.border = 'none' ..style.width = '100%' ..style.height = '100%' @@ -479,38 +470,36 @@ class _DocumentViewerModalState extends State { 'allow-scripts allow-popups allow-forms allow-pointer-lock allow-presentation allow-modals allow-downloads allow-popups-to-escape-sandbox', ); - container.append(iframe); - - // Use JavaScript to create and submit the form - // This is more reliable than Dart's form.submit() - final jsCode = ''' -(function() { - var form = document.createElement('form'); - form.method = 'POST'; - form.action = 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html'; - form.target = 'collabora-iframe-$viewId'; - form.style.display = 'none'; - - var input = document.createElement('input'); - input.type = 'hidden'; - input.name = 'WOPISrc'; - input.value = '$wopisrc'; - - form.appendChild(input); - document.body.appendChild(form); - - // Submit the form - setTimeout(function() { - form.submit(); - }, 50); -})(); + // Create an HTML page with an auto-submitting form + final htmlContent = ''' + + + + Loading... + + +
+ +
+ + + '''; - final script = html.ScriptElement() - ..type = 'text/javascript' - ..text = jsCode; - - html.document.body!.append(script); + // Set iframe src to a data URL with the form + final dataUrl = 'data:text/html;charset=utf-8,${Uri.encodeComponent(htmlContent)}'; + iframe.src = dataUrl; + + // Create a container + final container = html.DivElement() + ..style.width = '100%' + ..style.height = '100%' + ..style.margin = '0' + ..style.padding = '0' + ..style.overflow = 'hidden' + ..append(iframe); return container; });