简体   繁体   中英

Javascript async functions doesn't work in android chrome from js in url bar

I made a simple script to run in my android chrome. It comes that there are 2 scenarios working differently:

first one javascript:(alert("try")) works with no problems

second one javascript:(async function test(){alert("try")};test()) does NOT work

obv it's not what i am trying to do but in my desired script i need an await or a generic sleep. What can i do?

edit: the curious thing is that setInterval works fine... but javascript:(let prova = "try";alert(prova)) doesn't work

edit2: i did it, it took a very bad headache but now works. There are things that doesn't work for some reason but a workaround can always be found

here's what's the final working version

javascript:(setInterval(() =>{setTimeout(() => {document.querySelector('.nameofthetextareaselector').value="value i wanted to put here";document.querySelector('.nameofthebuttontosend').click();new Promise(resolve => setTimeout(() => {document.querySelector('.nameofthesecondbutton').click()},2000));resolve},2000)},5000))

It edits the textarea, send it, click another button after some seconds and repeat

things that not worked: assign anything with let, const or directly the name of the variable, nesting promises, using async-await, using try-catch, etc...

Now i am happy that all works but i want to know why all these things doesn't seem to work (only on android chrome, on windows chrome all these things worked)

您现在所做的只是声明一个函数而不调用它,您可以在 javascript 函数的末尾添加()以立即执行它。

javascript:(async function test(){alert("try")}())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM