ClericPy / ichrome

Chrome controller for Humans, based on Chrome Devtools Protocol(CDP) and python3.7+.
https://pypi.org/project/ichrome/
MIT License
235 stars 29 forks source link

怎么注入js在页面js加载之前? #59

Closed lalalatutu closed 3 years ago

lalalatutu commented 3 years ago

如题:

url = 'http://wcjs.sbj.cnipa.gov.cn/' 
await tab.js("""xxxx""")  # 此时注入js,页面还不存在,当goto时,页面就刷新了
await tab.goto(url)  # 在打开的同时,页面未加载js时,注入我的js
ClericPy commented 3 years ago

https://github.com/ClericPy/ichrome/blob/master/ichrome/async_utils.py#L1766

其实就是 cdp 里的 Page.addScriptToEvaluateOnNewDocument https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-addScriptToEvaluateOnNewDocument

lalalatutu commented 3 years ago

如果是通过一个页面,点击某个a标签,新打开的窗口,这种怎么在加载之前注入js呢

ClericPy commented 3 years ago

应该一个样吧, 没有试验过