diff --git a/modules/ui_gradio_extensions.py b/modules/ui_gradio_extensions.py index ed57c1e98..73ddef901 100644 --- a/modules/ui_gradio_extensions.py +++ b/modules/ui_gradio_extensions.py @@ -1,4 +1,5 @@ import os +import re import gradio as gr from modules import localization, shared, scripts, util @@ -49,12 +50,21 @@ def css_html(): return head +re_preconnect = re.compile(rb']*)?/?>') + + def reload_javascript(): js = javascript_html() css = css_html() def template_response(*args, **kwargs): res = shared.GradioTemplateResponseOriginal(*args, **kwargs) + + # remove preconnects + res.body = re_preconnect.sub(b'', res.body) + # replace iframeResizer with local version + res.body = res.body.replace(b'src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.6/iframeResizer.contentWindow.min.js"', b'src="webui-assets/js/iframe-resizer/4.3.6/iframeResizer.contentWindow.min.js"') + res.body = res.body.replace(b'', f'{js}'.encode("utf8")) res.body = res.body.replace(b'', f'{css}'.encode("utf8")) res.init_headers()