无法在“DOMWindow"上执行“postMessage":提供的目标源(“<URL>")与收件人窗口的源(“<URL>")不匹配 [英] Failed to execute &#39;postMessage&#39; on &#39;DOMWindow&#39;: The target origin provided (&#39;&lt;URL&gt;&#39;) does not match the recipient window&#39;s origin (&#39;&lt;URL&gt;&#39;)

查看:57
本文介绍了无法在“DOMWindow"上执行“postMessage":提供的目标源(“<URL>")与收件人窗口的源(“<URL>")不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:无法在DOMWindow"上执行postMessage":提供的目标源(")与收件人窗口的源(")不匹配).

我的页面按我希望的方式运行(我没有注意到任何不受欢迎的行为),但我从不喜欢忽略控制台中的错误,尤其是在我什至不了解根本原因的情况下.

My page operates as I'd hoped (I don't notice any unwanted behavior), but I never like ignoring errors in my console, especially if I don't even understand the root cause.

我的问题不是重复的,因为我已经研究了所有这些问题,但没有一个答案有效:

My question is NOT A DUPLICATE because I've already studied all of these questions but none of the answers worked:

我已经在使用 https.

我已经尝试将 playerVars 设置为 {origin: window.location.origin}.

I've already tried setting playerVars to {origin: window.location.origin}.

我已经尝试过设置 host.

我已经尝试过更改 iframe 的可见性.

I've already tried changing the visibility of the iframe.

等等.

var playerVars = {origin: window.location.origin};//https://stackoverflow.com/a/50518247/470749
window.onYouTubeIframeAPIReady = function () {
    for (var i = 0; i < youtube.length; i++) {
        var youtubeLazyEl = youtube[i];
        var videoId = youtubeLazyEl.dataset.v;
        players[videoId] = new YT.Player(videoId, {
            videoId: videoId,
            //host: 'https://www.youtube.com', //https://stackoverflow.com/a/47914456/470749
            //playerVars: playerVars,
        });
    }
};

想法?

推荐答案

TLDR;不是真正的答案,但可能有助于谷歌工程师追踪这个问题.

TLDR; not really an answer, but may possibly assist the google engineers in tracking down this issue.

我注意到只有在创建多个播放器时才会出现这个问题.

I have noticed the issue only surfaces for me when creating more than one player.

我有一个 页面,可以创建多个玩家来填充滚动条查看.

I've a page that creates multiple players to populate a scroll view.

我注意到我收到的错误消息比创建的玩家少,所以添加了 一个开关,强制页面只创建一个玩家然后忽略所有其他请求.

I noticed I was getting one less error message than there were players created, so added a switch that forces the page to only create one player then ignore all other requests.

自定义开关代码:永久链接

 createOnePlayerOnly = location.search.indexOf('oneplayer')>=0 ? true : false,  

这会导致单个播放器加载正常,没有错误(还有与 chromecast 扩展程序不再随 chrome 一起提供的其他错误,这些错误与 AFAIK 无关)

this causes a single player to load fine, with no errors (there are other errorsrelated to a chromecast extension no longer shipped with chrome, which are unrelated AFAIK)

始终创建每个播放器 通过始终设置原点和小部件的相同代码

    playerVars: info.playerVars || {
      fs: 1,
      controls: 0,
      playsinline: 0,
      enablejsapi: 0,
      modestbranding: 1,
      disablekb: 1,
      autohide: 1,
      autoplay: 0,
      loop: 0,
      volume: 0,
      iv_load_policy: 3,
      origin: location.href,
      widget_referrer : location.href
    }
  

因此,当创建其他播放器时,iframe 代码可能无法从选项中正确获取原始值.不知道为什么会这样,但这可能与缓存或范围问题有关.

So it's possible that the iframe code doesn't pick up the origin value from the options correctly when additional players are made. not sure why that might be, but it might be to do with caching, or scoping issues.

这篇关于无法在“DOMWindow"上执行“postMessage":提供的目标源(“<URL>")与收件人窗口的源(“<URL>")不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆