JavaScript注入window.addEventListener不起作用

huangapple go评论64阅读模式
英文:

Javascript Inject window.addEventListener not working

问题

我想注入 https://app.uniswap.org/#/swap
并且我在 Chrome 控制台中输入了 "document.body.addEventListener('click',function(event){console.log(event)})"。
我可以正常点击其他地方来获取事件。但是在点击选择 ETH 后,在弹出的模块对话框中,我无法通过点击来获取事件。

我想知道是什么导致无法获取点击事件。

英文:

I want to Inject https://app.uniswap.org/#/swap.
And I Input "document.body.addEventListener('click',function(event){console.log(event)})" in chrome console.
I can get the event normally by clicking other places. But after clicking to select ETH, in the pop-up module dialog box, I can’t get the event by clicking

I want to know what caused the failure to get the click event

答案1

得分: 0

I think you mean theres no event on the open modal.. because otherwise it works for me also.
这里好像是指打开模态框时没有事件触发,否则对我也有效。

it seems there are another click event from the reach-portal element which will be do as CBroe sais above a stopPropation or something else. If you remove the second event listener from the reach-portal you are able to do it.
看起来在reach-portal元素上还有另一个点击事件,可以像CBroe上面说的那样使用stopPropation或其他方法来处理。如果从reach-portal中移除第二个事件监听器,你就能够做到这一点。

Or, change the click event to "mousedown" or something else will work in this case.
或者,将点击事件更改为“mousedown”或其他事件也可以在这种情况下起作用。

update:
更新
Or even easier, add useCapture to the addEventListener.
或者更简单的方法是,给addEventListener添加useCapture参数。
document.body.addEventListener('click', function(event) { console.log(event) }, true)

英文:

I think you mean theres no event on the open modal.. because otherwise it works for me also.
it seems there are another click event from the reach-portal element which will be do as CBroe sais above a stopPropation or something else. If you remove the second event listener from the reach-portal you are able to do it.

Or, change the click event to "mousedown" or something else will work in this case.

update:
Or even easier, add useCapture to the addEventListener.
document.body.addEventListener('click',function(event){console.log(event)},true)

huangapple
  • 本文由 发表于 2023年4月19日 15:11:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76051662.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定