diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.js b/addons/website/static/src/client_actions/website_preview/website_preview.js index b30d6b8e27e..b13ea32e837 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.js +++ b/addons/website/static/src/client_actions/website_preview/website_preview.js @@ -419,6 +419,21 @@ export class WebsitePreview extends Component { }); } + /** + * This method is called when the page is unloaded to clean + * the iframefallback content. + */ + _cleanIframeFallback() { + // Remove autoplay in all media video iframes urls so videos are not + // playing in the background + const iframesEl = this.iframefallback.el.contentDocument.querySelectorAll(".media_iframe_video iframe"); + for (const iframeEl of iframesEl) { + const url = new URL(iframeEl.src); + url.searchParams.delete('autoplay'); + iframeEl.src = url.toString(); + } + } + _onPageUnload() { this.iframe.el.setAttribute('is-ready', 'false'); // Before leaving the iframe, its content is replicated on an @@ -431,6 +446,7 @@ export class WebsitePreview extends Component { this.iframefallback.el.contentDocument.body.replaceWith(this.iframe.el.contentDocument.body.cloneNode(true)); this.iframefallback.el.classList.remove('d-none'); $().getScrollingElement(this.iframefallback.el.contentDocument)[0].scrollTop = $().getScrollingElement(this.iframe.el.contentDocument)[0].scrollTop; + this._cleanIframeFallback(); } } _onPageHide() { diff --git a/addons/website_slides/__manifest__.py b/addons/website_slides/__manifest__.py index 59fc539da0e..be125b6fefb 100644 --- a/addons/website_slides/__manifest__.py +++ b/addons/website_slides/__manifest__.py @@ -72,6 +72,7 @@ Featuring 'assets': { 'web.assets_backend': [ 'website_slides/static/src/activity/**/*', + 'website_slides/static/src/client_actions/website_preview/website_preview.js', 'website_slides/static/src/slide_category_one2many_field.js', 'website_slides/static/src/slide_category_list_renderer.js', 'website_slides/static/src/scss/slide_views.scss', diff --git a/addons/website_slides/static/src/client_actions/website_preview/website_preview.js b/addons/website_slides/static/src/client_actions/website_preview/website_preview.js new file mode 100644 index 00000000000..8b53487dd8b --- /dev/null +++ b/addons/website_slides/static/src/client_actions/website_preview/website_preview.js @@ -0,0 +1,21 @@ +/** @odoo-module **/ + +import { patch } from 'web.utils'; +import { WebsitePreview } from '@website/client_actions/website_preview/website_preview'; + +patch(WebsitePreview.prototype, 'website_slides_website_preview', { + /** + * @override + */ + _cleanIframeFallback() { + // Remove autoplay in all youtube videos urls so videos are not playing + // in the background + const playersEl = this.iframefallback.el.contentDocument.querySelectorAll('[id^=youtube-player]'); + for (const playerEl of playersEl) { + const url = new URL(playerEl.src); + url.searchParams.delete('autoplay'); + playerEl.src = url.toString(); + } + return this._super(...arguments); + } +});