通过注入的JavaScript强制React触发事件 [英] Force React to fire event through injected JavaScript

查看:50
本文介绍了通过注入的JavaScript强制React触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做什么

我目前正在为Web-Whatsapp编写一个小型聊天机器人.由于易于js注入,我决定使用chrome扩展名.有一个语音消息按钮,当您开始键入内容时,该按钮会切换为用于发送文本的按钮. React删除了语音消息元素并渲染了发送按钮.

I am currently writing a little chat bot for Web-Whatsapp. I decided to use a chrome extension because of the easy js-injection. There is a voice-message button which switches to a button for sending text as you start typing something. React deletes the voice-message element and renders the send button.

问题

这整个过程是事件驱动的.我正在通过DOM设置Text,而不会触发react事件.我尝试模拟按键,但是出于安全原因,似乎chrome的v8禁用了所有模拟按键的方法.我还尝试了一点操作HTML,但是在对Elements进行更改后,反应停止了.我也尝试过使用jQuery函数,但是那也不起作用.

This whole process is event driven. I am setting the Text through DOM which does not trigger the react event. I tried to simulate a keypress but it seems like chrome´s v8 disabled all ways to simulate keypresses for security reasons. I also tried to manipulate the HTML a bit but react stopped working after i made changes to the Elements. I also tried the jQuery function for that but that didn't work either.

对无用的内容的引用:

Chrome中的Keydown Simulation正常启动,但不是正确的密钥

https://api.jquery.com/keypress/

问题

有什么方法可以强制React触发事件吗?或对此有任何解决方法?

Is there any way to force React firing the event? Or any kind of workaround for this?

推荐答案

解决方案" 经过两天的研究,我不得不承认,出于安全原因,这显然是不可能的.如果遇到像我一样的情况,您不应浪费时间尝试解决此问题,而不仅仅是寻找一个好的解决方法.如果知道了,我将在这里为WebWhatsapp-bot更新我的内容.

"Solution" After two days of research I have to admit that this is obviously not possible on the way I tried it for security reasons. If you ever get into the same situation like me you shouldn´t waste time on trying to fix this, rather than just looking for a good workaround. I will update mine for the WebWhatsapp-bot here if i figured it out.

这篇关于通过注入的JavaScript强制React触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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