diff --git a/src/slic3r/GUI/PluginWebDialog.cpp b/src/slic3r/GUI/PluginWebDialog.cpp index fdaf6c7a23..1808f21ce9 100644 --- a/src/slic3r/GUI/PluginWebDialog.cpp +++ b/src/slic3r/GUI/PluginWebDialog.cpp @@ -48,13 +48,14 @@ std::string plugin_defaults_user_script() return WebViewHostDialog::document_start_injector(css, "orca-plugin-defaults", "beforeend"); } -// Injected into every page at document start (before the plugin's own scripts). -// Defines window.orca as the only host surface the page may use. It references -// window.wx lazily (at call time) so it never races the backend's deferred -// registration of the "wx" message handler. Guarded against double-injection so -// it is harmless if also prepended. +// Injected into the top-level page at document start (before the plugin's own +// scripts). Defines window.orca as the only host surface the page may use. It +// references window.wx lazily (at call time) so it never races the backend's +// deferred registration of the "wx" message handler. Guarded against +// double-injection so it is harmless if also prepended. constexpr char ORCA_BRIDGE_JS[] = R"JS( (function () { + if (window.top !== window.self) return; if (window.orca) return; var handlers = []; function send(kind, data) { diff --git a/src/slic3r/GUI/Widgets/WebViewHostDialog.cpp b/src/slic3r/GUI/Widgets/WebViewHostDialog.cpp index 9f4718160e..5e6026d1cf 100644 --- a/src/slic3r/GUI/Widgets/WebViewHostDialog.cpp +++ b/src/slic3r/GUI/Widgets/WebViewHostDialog.cpp @@ -96,6 +96,9 @@ std::string WebViewHostDialog::document_start_injector(const std::string& markup const std::string literal = nlohmann::json(markup).dump(); std::string s; s += "(function(){"; + // wxWebView's AddUserScript runs in child frames too (including cross-origin + // frames on WebView2). Host theme state belongs only to the top-level page. + s += "if(window.top!==window.self)return;"; s += prelude; s += "var css=" + literal + ";"; s += "function inject(){";