How send JavaScript or jquery commands on webview tasker elements?

这一生的挚爱 提交于 2019-12-12 10:16:50

问题


  1. I created a scene and webview1 element with:

    • mode: url
    • source: www.google.com

  2. created a task to show scene
  3. Now, I want to create a JavaScript task to send to the Webview:

    • $("#q").val("Chuck Norris");
    • $("button#search").click();

PS: I don't want to just execute Javascript, I want to execute it in the opened Webview.


回答1:


I do not really understand what would possibly be the point of creating webview scenes and acting on them, when what you need can be achieved "silently". You can query webpages and traverse their DOM structure without even viewing.

Tasker does support JavaScript and loading external libraries. Have a look here for more detailed explanation: tasker.wikidot.com/userguide-en:javascript

Alternatively, you can give SL4A a go: code.google.com/p/android-scripting/

Have you tried adding an action (either Javascript or SL4A) to the Page Loaded event on WebView properties?

// edit

@fredericoallan

What you need to do/use is to play with HTTP GETand HTTP POST for sending headers and handling sessions (I do recommend tasker plugin: RESTask for that as it allows sending headers). But first things first.

prerequisities

To be able to send headers and set session, you need to find out what headers and cookies are being sent when you open the page and/or click login button. To see that (if you're using chrome) you can use chrome's built in developer tools. Just right click somewhere on the page and select "inspect element". In the window that'll appear, go to tab "network"

session

Just refresh the page and observe the network tab. First request on the list should be GET method and type text/html. Click it. Select headers tab in the right pane. You should now notice, that our session ID is being stored in a cookie under PHPSESSID. We're gonna need that information later

headers

To be able to log in, you need to have an open session, otherwise server will deny you access. We've checked how and where session key is stored, so we can have a look at log-in headers (we need to know how your username and passord are being sent to the server).

Having developer tools still open, click login button. Content of the network tab should have changed. What is interesting for us, is the first request sent ( index.php?act=login, method POST, type text/html). When clicked, we should see things like remote address, request URL, request method and little bit down below Form Data containing username, password, submit attributes.

building Tasker's task

Now, having gathered all that information, we can proceed to building a task, that will log us in.

  1. create HTTP GET action (with no additional parameters/headers) pointing to redmine.demo.org. In a server response you'll receive the HTML markup, headers and cookie to be set.
  2. extract %sessionID from the cookie (using variable search and replace or variable section)
  3. create HTTP POST action pointing to https://www.untergrund.net/index.php?act=loginpost with a header: Cookie=%sessionID and parameters: username=%userid, password=%pass, PHPSESSID=%sessionID

you are now logged in. Response received will contain page that is diplayed upon login.

code example

HTTP loggin in (119)
A1: RESTask [ Configuration:REST call Package:com.freehaha.restask Name:RESTask Timeout (Seconds):30 ] 
A2: Test Variable [ Type:Length Data:%rthdr_set_cookie Store Result In:%sesslen ] 
A3: Variable Section [ Name:%rthdr_set_cookie From:1 Length:%sesslen-8 Adapt To Fit:Off Store Result In:%sessionID ] 
A4: RESTask [ Configuration:REST call Package:com.freehaha.restask Name:RESTask Timeout (Seconds):30 ] 


来源:https://stackoverflow.com/questions/26700266/how-send-javascript-or-jquery-commands-on-webview-tasker-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!