gpt4 book ai didi

javascript - Shadow DOM 不清楚

转载 作者:行者123 更新时间:2023-11-30 10:03:00 26 4
gpt4 key购买 nike

我需要访问具有 Shadow DOM 的已打开窗口的 body 元素。在您的浏览器上运行此代码(您需要在您的浏览器上禁用第三方安全):

<script type="text/javascript">
janela = window.open("http://www.google.com.br");

window.setTimeout(

function() {

console.log(janela.window.document.body.innerHTML);

},
5000

);
</script>

如果您在控制台看到一个空字符串。现在更改 URL http://www.google.com.brhttp://www.bing.com.br它工作正常:BODY innerHTML 显示在控制台中。

我看到 Google 现在正在使用 Shadow DOM,这可能是我遇到问题的原因。在浏览器中打开 Google.com -> F12,你会看到有一个 #shadow-root 元素,我认为这会造成我的问题。我怎样才能绕过它并访问 DOM?

最佳答案

Shadow DOM 与此无关。您的浏览器不想让任何随机网站打开诸如 gmail.com 之类的网站并阅读他们在那里看到的任何内容。如果是这样,那么只要您登录到您的 Gmail 帐户,您访问的任何网站都可以读取您的所有电子邮件。

请阅读“跨源脚本API访问”部分here .

JavaScript APIs such as iframe.contentWindow, window.parent, window.open and window.opener allow documents to directly reference each other. When the two documents do not have the same origin, these references provide very limited access to Window and Location objects, as described in the next two sections.

关于javascript - Shadow DOM 不清楚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30623394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com