Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,怎么在一个tab里切换到内嵌的iframe?Hi,How to switch_to a inner iframe in a tab? #101

Open
lyx1104 opened this issue Aug 25, 2022 · 5 comments

Comments

@lyx1104
Copy link

lyx1104 commented Aug 25, 2022

看了很久的源码也没有找到。。。

@ClericPy
Copy link
Owner

呃, 不用太纠结源码, 搜不到就说明没有, 目前只放了日常比较常用而且简单实现的功能, 你说的那个要 CDP 里面很多 domain 关联, 因为没用上所以就没搞...

一般我遇到 iframe 用另外两个方式就避开了, 就没用官方那套:

  1. 用 JS 在外层操作内层对象
  2. 有时候 iframe 的 src 直接 tab.goto 过去也可以直接当普通 tab 操作...

@why2lyj
Copy link
Contributor

why2lyj commented Nov 3, 2022

呃, 不用太纠结源码, 搜不到就说明没有, 目前只放了日常比较常用而且简单实现的功能, 你说的那个要 CDP 里面很多 domain 关联, 因为没用上所以就没搞...

一般我遇到 iframe 用另外两个方式就避开了, 就没用官方那套:

  1. 用 JS 在外层操作内层对象
  2. 有时候 iframe 的 src 直接 tab.goto 过去也可以直接当普通 tab 操作...

我遇到了一个网站,要点击iframe里的一个按钮。
1、然后我用了JS模拟点击,告诉我一个类似这个按钮被阻挡,无法点击的错误。
2、我选择 tab.goto 到 iframe 的 src , 界面告诉我 Access Denied。

因为不熟悉CPD,我最后无奈的用了操作鼠标直接点击的方式处理的。我觉得我的代码不干净了。

@ClericPy
Copy link
Owner

ClericPy commented Nov 3, 2022

goto 不过去那就是做了保护... 你在 iframe 里面运行 JS 还说阻挡那就挺麻烦了, dispatch 鼠标点击 Event 到某个 position 有用么, 这种我只在非 iframe 的 root node 上试过, 在 iframe 里面我平时用的最多的就是执行 JS 函数或者获取某些东西, 你都提示被阻挡了(咋提示的?) 那也不好办啊

@why2lyj
Copy link
Contributor

why2lyj commented Feb 10, 2023

找了一个有意思的例子:

https://octocaptcha.com

js:

document.getElementById('fc-iframe-wrap').contentWindow.document.getElementById('home_children_button').click()

return:

Uncaught DOMException: Blocked a frame with origin "https://octocaptcha.com" from accessing a cross-origin frame.

@ClericPy
Copy link
Owner

这是禁止跨域运行啊, 走 CDP node 是不是可以在里面执行点什么. 现在这些前端弄得不想干爬虫了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants