I'm trying to use the new evaluateJavascript method in Android 4.4, but when i try to evaluate this javascript code
browser.evaluateJavascript("(function() { document.getElementById('login').value='"+username+"'; document.getElementById('password').value='"+password+"'; document.getElementsByTagName('input')[2].click(); return '';})();",new ValueCallback<String>() {
#Override public void onReceiveValue(String s) {
}
});
the app crashes returning:
Fatal signal 6 (SIGABRT) at 0x00006225 (code=-6), thread 25125
the javascript code is correct, because with the old way
browser.loadUrl("javascript:(function() { ...
it works.
doing some tests, i've found that the problem is when is executed the function
document.getElementsByTagName('input')[2].click();
the input is a submit button, that sends a form.
how can i do to fill the form and send it?
As per the Trigger form submission in chrome javascript console question it might be simpler to call submit() on the form. I have tried reproducing your problem but didn't get a crash - using both click() on the submit button and submit() on a form worked fine for me.
The SIGABRT looks quite bad though, are you calling the API from the UI thread? If no, then try that first. If it's called from the UI thread then you definitely should file a bug on the Android Open Source Project Issue Tracker. Ideally you'd include the the output of adb bugreport immediately after the crash and a sample app demonstrating the issue.
Related
I'm having a simple Flutter plugin that communicates through a MethodChannel with some native Android code. Here's a simple example how the methods provided by the plugin look like:
Future<void> doSomethingImportant(int address, SomeImportantData importantData) async {
String jsonButStillImportant = jsonEncode(importantData.toJson());
return methodChannel.invokeMethod('doSomethingImportant', {"address": address, "data": jsonButStillImportant});
}
When the doSomethingImportant() (java) method is done, it delivers the result to Flutter by calling:
public void onSuccess(Result result, Object value) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
#Override
public void run() {
result.success(value);
Log.d("Debug", "Why does this occasionally cause a timeout at Flutter?!?");
}
});
}
Then, during tests, the method is called like this:
void _someTestMethod() async {
await doSomethingImportant(anAddress, theMostImportantDataInTheWorld).timeout(const Duration(seconds: 1)).catchError((e) {
print("Something's wrong here: "+e.toString());
return;
});
}
This is working well most of the time. Sometimes, however, the test fails because doSomethingImportant() runs into a timeout, and the following shows up at logcat:
2021-12-15 19:56:50.919 D/Debug: Why does this occasionally cause a timeout at Flutter?!?"
2021-12-15 19:56:51.697 I/flutter: Something's wrong here: TimeoutException after 0:00:01.000000: Future not completed
Now I'm wondering what can possibly cause the timeout and how to prevent it. What's noticeable is that the timeout message always appears about 700-800 milliseconds after result.success() was called.
Edit 1:
The problem is that sometimes the future does not complete, even though result.success() is called. This happens only sporadically, but if it does, the timeouts purpose is to gracefully exit the calling function. Simply removing the timeout is unfortunately not an option, because it would block forever.
Edit 2 - some more background information:
Please note that the above code snippets of doSomethingImportant() and _someTestMethod() are just examples to illustrate how the methods look like. (Except onSuccess(), this one's an exact copy from the production code).
The actual plugin controls a Bluetooth Mesh network. _someTestMethod() sends and receives data to verify that the mesh network and the firmware running on the individual nodes are doing what they are supposed to do. The logic in _someTestMethod() looks like this:
Send data into the mesh.
Read data from the mesh.
Verify that the read data matches the expected result.
The await/timeout() approach has been chosen because each step depends on the successful completion of the previous step. Nesting those calls in .then() callbacks would be an alternative, but I simply prefer the top-to-bottom await/timeout()-spaghetti-code to nested .then() callbacks.
The problem is, that every now and then, MethodChannel.Result.success() is called at Android, but Flutter does not complete the Future. If that happens, the Future stays uncompleted for all of eternity and logcat does not tell anything neither.
Again, this happens only sporadically. Most of the time it is working just fine.
Now the question is, what's wrong here? Is there any other way to convince the Future to complete? Any ideas are welcome Thank you!
Now I'm wondering what can possibly cause the timeout and how to prevent it. What's noticeable is that the timeout message always appears about 700-800 milliseconds after result.success() was called.
Do you have any ideas how to fix (or even debug) the source of this timeout? Thank you!
You are using .timeout(const Duration(seconds: 1)), so it times out. If you don't want it to timeout, remove that code.
Can you clarify what the issue you are facing is? Are you dissapointed that your work is not completed within 1 second, or have you just not realized you added the timeout?
After your edit:
Using await + timeout does not gracefully exit the function, it literally throws an error. To "gracefully" handle this situation where a Future might not immediately complete, instead of using await, use .then instead. That way, any code below your platform method invocation won't be delayed. Of course, you won't have the result in your platform method. If you need that result immediately, then neither await + timeout + catchError nor .then will help you.
Arbitrarily choosing 1 second (or any other time) to run the code and then throw an error is guaranteed to bring issues, especially in a production app with users using all sorts of devices. On slow devices, this could legitimately happen, you should handle it gracefully. It might also hurt debugging, lets say you make a platform method invocation and then pause at a breakpoint, the code will throw the error, because the timer still runs. What an awful debugging experience. I highly recommend not using timeout in this case.
To help debug:
Open the android project window in Android Studio, and either:
Run the debugger from this window (which launches the Android app) with the debugger attached
Run the debugger from Flutter window, and attach the android project window debugger to your running app.
app
Place a breakpoint on line result.success(value);, and observe if it is being called.
Perhaps new Handler(Looper.getMainLooper()).post(new Runnable() { is never being called, in that case you have to understand why that runnable is never posted. I'm not sure if you actually ran your example posted above, or if you're just trying to debug a more complex application.
Perhaps another issue is happening, and a more useful error could be shown. (You didn't share many logs, check out logcat or pidcat.). A wild guess would be that the Main thread is busy right now, doing some work that you shouldn't have made it do on the main thread 😅🙈, or just doing Flutter work (less likely).
I have a mscrm form, when load it for a specific clients I get an error but when I load it for other clients it works fine (no errors), the error was about process on my form which I try to hide on onload event and it is null, so I added an if before hiding it and everyting works fine:
Solution:
if (!!Xrm.Page.ui.process) {
Xrm.Page.ui.process.setVisible(false);
}
My question is, why it happens on some cliets forms and not all forms? it is the same form the same JS what is the reason?
When I get those kind of problem, I put my code in a timeout like so:
setTimeout(function(){/*some code*/},0)
It put your code at the end of the stack as the last thing to do.
I want a solution for the following scenario:
In a page I am uploading an xml and while clicking on the upload button I am going to recieve an pop up for confirmation (I am able to detect this), after this again I am recieving an pop up which I am not able to detect (The page is still getting loaded in the browser ). Kindly help me to sort this out .
I have tried with many solutions for this like: get window ids,titles .
Thanks
You can you use -
$sel->get_confirmation()
This retrieves the message of a JavaScript confirmation dialog generated duringthe previous action. By default, the confirm function will return true, having the same effectas manually clicking OK. This can be changed by prior execution of thechooseCancelOnNextConfirmation command. If an confirmation is generatedbut you do not get/verify it, the next Selenium action will fail.
NOTE: under Selenium, JavaScript confirmations will NOT pop up a visibledialog.
NOTE: Selenium does NOT support JavaScript confirmations that aregenerated in a page's onload() event handler. In this case a visibledialog WILL be generated and Selenium will hang until you manually clickOK.
Returns the message of the most recent JavaScript confirmation dialog.
You should always refer to WWW::Selenium - Perl Client while working with perl and RC.
I have found what is the problem #amey ...I am tring to upload an file which is not actually not permitted due to some security issues with firefox... There was actually an work around for this
http://cakebaker.42dh.com/2006/03/29/file-upload-with-selenium/
.....Which will not work with latest Selenium RC with Firefox since firefox have removed the support for enablePrivilege
https://support.mozilla.org/en-US/questions/944433.
So it is a mandate to shift to WEBDRIVER it seems.............
http://git.erp5.org/gitweb/erp5.git/commitdiff/06898bbfae4f238b7e79ce05048646529216064e
Thanks for your support....
my solution was using the function:
$driver->execute_script("Events.invokeEvent('UserDetailPage:UserDetailScreen:UserDetailToolbarButtonSet:UserDetailToolbarButtons_DeleteUserButton_act', true);");
analyzing what the javascript code does when the Accept button was pressed. and executing that code in the function.
I think that I've found a bug in the add-on SDK. When I try to load a tab doing something like this:
var t = tabs.open({
url: linkURL,
inBackground: true,
onReady: closeTab(this)
});
And the URL is an image. The onReady event is never fired.
Is that the expected behaviour?
Thanks
I'm not sure whether this counts as a bug but you should probably file a bug report to see what the developers think about it. The problem is that the SDK waits for the DOMContentLoaded event to recognize that the tab is ready - but Gecko doesn't fire this event for image documents. The SDK could use a web progress listener instead, these work regardless of the document type.
My Flash app calls:
Facebook.ui("pay.prompt", data, onPayCallback, "iframe");
which works correctly on all browsers, until a recent change in the embedding of the swf file. I now use wmode="window" which gives much better performance in IE (previously I used "opaque").
When the facebook credits popup appears, the game is now hidden as expected. It returns correctly when the popup is closed. However, on IE (version 9, other versions are untested) the callback is never called.
Any ideas please?
Did you manage to get any further on this?
In my case the javascript callback is triggered, and the call to the flash function is also being made, but throws an error "Object required".. with a little bit more digging (using IE's developer tool) the addcallBack function in the swf was null..