Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cordova SQLIte Plugin Not Working in Child Windows #368

Open
rbahadur opened this issue Oct 19, 2015 · 15 comments
Open

Cordova SQLIte Plugin Not Working in Child Windows #368

rbahadur opened this issue Oct 19, 2015 · 15 comments

Comments

@rbahadur
Copy link

Hello,

My application is working fine when I do not have any pops, but I have a requirement where I need to call a window (POP UP) in which data is loading in iframe, In that I need to fetch some details from data base, but when I am trying to connect to Data base, connection is working, but when I am trying below statement.

db.transaction( function(tx){

Control is not coming after this line >>
tx.executeSql(queryString,[],function(tx,results){

},function(tx,error){
console.log("Error while querying Quote from DB"+error.message);
});
}, errorCB, function(tx){
console.log("Successfully quried Parent Account list"+JSON.stringify(parentaccountlistData));
});

When I debug the code the controll is going to cordova js in the below method, and bridgeSecret value is coming -1.

function pollOnce(opt_fromOnlineEvent) {
if (bridgeSecret < 0) {
// This can happen when the NativeToJsMessageQueue resets the online state on page transitions.
// We know there's nothing to retrieve, so no need to poll.
return;
}
var msgs = nativeApiProvider.get().retrieveJsMessages(bridgeSecret, !!opt_fromOnlineEvent);
if (msgs) {
messagesFromNative.push(msgs);
// Process sync since we know we're already top-of-stack.
processMessages();
}
}

@brodycj
Copy link
Contributor

brodycj commented Oct 19, 2015

This seems like an issue with cordova-android. Not sure when I will get a chance to test it. BTW cordova-ios supports multiple JS bridge communications methods (iframe or XHR), and it had some problems with the iframe method in the past which seem to have been fixed. Not sure if cordova-android supports multiple bridge communications methods as well.

For reference (iOS version):

@rbahadur
Copy link
Author

Is there any approach we can do it for android as well, because it is very important for us, other wise whole architecture need to be revisit.

@brodycj
Copy link
Contributor

brodycj commented Oct 19, 2015

You could use Web SQL or W3 local storage API if you target do not care about user backup capability and do not need to support the older Android versions.

@rbahadur
Copy link
Author

Thanks for the quick update, we are using Cordova V 1.8 and we have the given line in the file,the bridgemode value is coming as 0, and it is not working of window pop pup.
iOSExec.jsToNativeModes = jsToNativeModes;
iOSExec.setJsToNativeBridgeMode = function(mode) {
// Remove the iFrame since it may be no longer required, and its existence
// can trigger browser bugs.
// https://issues.apache.org/jira/browse/CB-593
if (execIframe) {
if (execIframe.parentNode) {
execIframe.parentNode.removeChild(execIframe);
}
execIframe = null;
}

function IOSExec(){
if (bridgeMode === undefined) {
bridgeMode = jsToNativeModes.IFRAME_NAV;
}
}

};
the bridgeMode value is coming as 0, and it is not setting the view mode

@brodycj
Copy link
Contributor

brodycj commented Oct 19, 2015

Can you guys try it with the new version of Cordova?

@rbahadur
Copy link
Author

We have tried in cordova latest JS file, but it is not working.
just to summarize, below is the flow.

I have an html page, where all the SQL queries are working fine, and I have link where I am opening a pop where the the content comes using Ifram, now in this Iframe when I am trying to connect to data base, it is not connecting and I am getting Java exception from Cordova

@brodycj
Copy link
Contributor

brodycj commented Oct 26, 2015

Please post the log output with the exception.

@rbahadur
Copy link
Author

Below is the stack trace.

Uncaught Error: Java exception was raised during method invocationcordova.js:967 pollOncecordova.js:958 pollOnceFromOnlineEvent
whitelist.js:25 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.
whitelist.js:25 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.
whitelist.js:25 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.
whitelist.js:25 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.

Below is the logs from log cat:

10-26 05:54:54.298: V/sqlg(13393): prepare db 0xaf0c0a08 sql COMMIT
10-26 05:54:54.299: V/sqlg(13393): sqlc_st_finish 0xaf217ac8
10-26 05:54:54.329: V/sqlg(13393): prepare db 0xaf0c0a08 sql BEGIN
10-26 05:54:54.329: V/sqlg(13393): sqlc_st_finish 0xaf217ac8
10-26 05:54:54.329: V/sqlg(13393): prepare db 0xaf0c0a08 sql SELECT mId,Id,Name,Catgr FROM Product ORDER BY Name
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_count 0xaf217ac8
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 0
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 0
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 0
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 1
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 1
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 1
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 2
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 2
10-26 05:54:54.331: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 2
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 3
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 3
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 3
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_count 0xaf217ac8
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 0
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 0
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 0
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 1
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 1
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 1
10-26 05:54:54.335: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 2
10-26 05:54:54.336: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 2
10-26 05:54:54.336: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 2
10-26 05:54:54.336: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 3
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 3
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 3
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_count 0xaf217ac8
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 0
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 0
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 0
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 1
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 1
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 1
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_name 0xaf217ac8 2
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_type 0xaf217ac8 2
10-26 05:54:54.337: V/sqlg(13393): sqlc_st_column_text_native 0xaf217ac8 2

10-26 05:55:29.581: V/sqlg(13393): sqlc_st_finish 0x95cdf6e8
10-26 05:55:30.675: I/Choreographer(13393): Skipped 65 frames! The application may be doing too much work on its main thread.
10-26 05:55:30.703: E/CordovaBridge(13393): Bridge access attempt with wrong secret token, possibly from malicious code. Disabling exec() bridge!
10-26 05:55:30.704: W/System.err(13393): java.lang.IllegalAccessException
10-26 05:55:30.704: W/System.err(13393): at org.apache.cordova.CordovaBridge.verifySecret(CordovaBridge.java:100)
10-26 05:55:30.704: W/System.err(13393): at org.apache.cordova.CordovaBridge.jsRetrieveJsMessages(CordovaBridge.java:81)
10-26 05:55:30.705: W/System.err(13393): at org.apache.cordova.engine.SystemExposedJsApi.retrieveJsMessages(SystemExposedJsApi.java:51)
10-26 05:55:30.705: W/System.err(13393): at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
10-26 05:55:30.705: W/System.err(13393): at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
10-26 05:55:30.705: W/System.err(13393): at android.os.Handler.dispatchMessage(Handler.java:102)
10-26 05:55:30.705: W/System.err(13393): at android.os.Looper.loop(Looper.java:135)
10-26 05:55:30.705: W/System.err(13393): at android.os.HandlerThread.run(HandlerThread.java:61)
10-26 05:55:30.730: I/chromium(13393): [INFO:CONSOLE(967)] "Uncaught Error: Java exception was raised during method invocation", source: file:///android_asset/www/cordova.js (967)
10-26 05:55:30.733: E/CordovaBridge(13393): Bridge access attempt with wrong secret token, possibly from malicious code. Disabling exec() bridge!
10-26 05:55:30.733: W/System.err(13393): java.lang.IllegalAccessException
10-26 05:55:30.733: W/System.err(13393): at org.apache.cordova.CordovaBridge.verifySecret(CordovaBridge.java:100)
10-26 05:55:30.733: W/System.err(13393): at org.apache.cordova.CordovaBridge.jsRetrieveJsMessages(CordovaBridge.java:81)
10-26 05:55:30.733: W/System.err(13393): at org.apache.cordova.engine.SystemExposedJsApi.retrieveJsMessages(SystemExposedJsApi.java:51)
10-26 05:55:30.733: W/System.err(13393): at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
10-26 05:55:30.733: W/System.err(13393): at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
10-26 05:55:30.733: W/System.err(13393): at android.os.Handler.dispatchMessage(Handler.java:102)
10-26 05:55:30.733: W/System.err(13393): at android.os.Looper.loop(Looper.java:135)
10-26 05:55:30.733: W/System.err(13393): at android.os.HandlerThread.run(HandlerThread.java:61)
10-26 05:55:30.745: I/chromium(13393): [INFO:CONSOLE(967)] "Uncaught Error: Java exception was raised during method invocation", source: file:///android_asset/www/cordova.js (967)
10-26 05:55:31.481: I/Choreographer(13393): Skipped 42 frames! The application may be doing too much work on its main thread.
10-26 05:55:36.612: I/chromium(13393): [INFO:CONSOLE(25)] "No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.", source: file:///android_asset/www/plugins/cordova-plugin-whitelist/whitelist.js (25)
10-26 05:55:39.567: I/chromium(13393): [INFO:CONSOLE(25)] "No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.", source: file:///android_asset/www/plugins/cordova-plugin-whitelist/whitelist.js (25)

@brodycj
Copy link
Contributor

brodycj commented Oct 26, 2015

This is definitely caused by the Cordova framework. Please raise an issue on the Cordova project thanks!

@rbahadur
Copy link
Author

Thanks for the update, can you please share the links where I can raise this issue.

@brodycj
Copy link
Contributor

brodycj commented Oct 26, 2015

I will log the issue later today or tomorrow. I want to provide absolute proof that the problem is with the framework and NOT this plugin.

@rbahadur
Copy link
Author

Thanks ...

@rbahadur
Copy link
Author

Hello Brody,

thanks for the update and raising the issue for us, I wanted to know, when they can fix the issue, so that we can ustilize the build for the project, as of now we have very tight deadline and we stuck with this issue.

It would be really help full for us, to know when we can get the fix from the Cordova

@brodycj
Copy link
Contributor

brodycj commented Oct 27, 2015

Hi Rah,

Thanks for the followup. To be honest, I am pretty swamped with a backlog of both paid work and bugs to be fixed in the free software. In addition, we have no way to predict when or even if they will fix the bugs in the Cordova framework. (The last two bugs that I submitted did not get fixed.)

Did you guys look at the InAppBrowser plugin in case it may work for you?

I highly recommend that you look for an alternative if you have such a tight deadline.

I noticed something else in your log: the whitelist plugin complained that there is no Content-Security-Policy tag. I am not sure if this has to do with the iframe or with your app in general.

If you are not ready to give up on the iframe, it would help me if you can publish a small project that tries to access the plugin from an iframe. I suggest you try a very simple sql statement such as SELECT 1 or SELECT UPPER('Some text') since we are really interested in getting the JS-Java bridge to work. If you make this project for me than I can investigate this.

Thanks,
Chris

@brodycj
Copy link
Contributor

brodycj commented Nov 5, 2015

FYI I recently discovered that a Cordova plugin can override the shouldAllowBridgeAccess method. If it always returns true it should be able to work with iframe. See the following lines: https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaPlugin.java#L235-L242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants