Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
My Carrier: none
Accepted Solution

ScriptException: No detail message

Hello!

 

I've got my BrowserField, I've got some HTML and JavaScript loaded, I do have a JavaScript function that should be executed via:

public void executeJS(String javascript) {
try {
ScriptEngine engine = mdBrowserField.getScriptEngine();
Object script = engine.compileScript(javascript);
engine.executeCompiledScript(script, null);
} catch (Throwable e) {
e.printStackTrace();
}
}

 

but this only produces: 

[5609.453] ScriptException
[5609.453] No detail message
[5609.453] net_rim_bb_browser_olympia-3(4EC5E80F)
[5609.468] DOMDataReader
[5609.468] readScriptObject
[5609.468] 0x295F
[5609.468] net_rim_bb_browser_olympia-4(4EC5E80F)
[5609.492] OlympiaScriptEngine
[5609.492] executeCompiledScript
[5609.492] 0x6EB6

 I am going to ask in the WebWorks forums as well, but if you've got any ideas, feel free to help,

 

thanks!

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: ScriptException: No detail message

Could you post your code please? At least enough if it for me to try and recreate the problem... some of the Java, some HTML and the whole JavaScript function and any functions it calls.

 

What device and OS version are you testing on?

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
My Carrier: none

Re: ScriptException: No detail message

Well, the content of the javascript String look like this: "callbackFunction(\"" + Base64String + "\");"

The javascript function thats executed is defined in one javascript file as:

function Api() {
...
this.setCallbackFunction(newCallbackFunction) {
callbackFunction = newCallbackFunction;
}
...
}

var api = new Api(),
callbackFunction = function () {};

 and then theres another javascript file that does the following:

var syncFinished = function (syncResponse) {
     var dif; // The ; should be a , but this shouldn't make a big difference regarding the issue, going to
// fix it and try it again syncResponse = JSON.parse(atob(syncResponse));

if (syncResponse) {
dif = Math.ceil(((syncResponse.download.max - syncResponse.download.arrayCount) / syncResponse.download.max) * 100);
}

$("#someDiv").text(dif);
...
refresh();
},
refresh = function() {
...
//Here I set off some xmlhttprequests that get cought and answered by Java, which could be an
//Issue, so Ill also try to put all the compile and execute script stuff into its own thread, the only
//other reason I could think of is that the javascript may be timed out because the
//JAVASCRIPT_TIMEOUT option in the BrowserFieldConfiguration doesn't have any effect, at best.
};

api.setCallbackFunction(syncFinished);
Please use plain text.
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
My Carrier: none

Re: ScriptException: No detail message

[ Edited ]

Sry, I forgot to mention that I am developing on a 9380 and the app should work on BB 6.0+

 

P.S.:And the currently installed version is v7.0.0.557 Plattform 9.32.0.59

P.P.S.: I tried to put all the javascript related stuff in another thread. and I fixed that minor ; error in js. still not working.

 

Well, but I dont get any exceptions anymore... Ill try to get the WebInspector working and see what it tells me...

 

Ok! I get the WebInspector working, and when I trigger the event that causes the javascript to be executed (or, well, to not be executed atm.) before connecting to the WebInspector via Safari it doesnt show me anything besides my sourcecode. On the other hand, if I connect to the WebInspector before triggering the mentioned event, the app simply crashes, no matter what. The app also crashes if I do anything else, like switching to another page, while Safari is connected to the WebInspector. So all in all the WebInspector has proven to be utterly useless, pretty much reminds me of jsHybugger on Android... going to try a stupid alert at the start of syncFinished() now...

Please use plain text.
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
My Carrier: none

Re: ScriptException: No detail message

[ Edited ]

I added an alert("syncFinished"); at the beginning of syncFinished() in the javascript code, and it didn't pop up, so I can definitely say that the function is not being called at all.

 

I just changed the executeJS method a little:

	public void executeJS(final String javascript) {
		try {
			Runnable jsr = new Runnable() {
				public void run() {
					mdBrowserField.displayContent(javascript.getBytes(), "text/javascript", "javascript:" + javascript);
//					ScriptEngine engine = mdBrowserField.getScriptEngine();
//					Object script = engine.compileScript(javascript);
//					engine.executeCompiledScript(script, null);
					try {
						Thread.currentThread().join();
					} catch (Throwable e) {
						e.printStackTrace();
					}
				}
			};
			Thread jsrThread = new Thread(jsr);
			jsrThread.start();
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

And guess what, the alert is firing!

Thats absolutely great, now I just need to find out where its failing now.

Please use plain text.
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
My Carrier: none

Re: ScriptException: No detail message

[ Edited ]

Well, I almost did it... the thing is that the javascript I am sending through to the browserfield is only executed once per app start... all subsequent tries to execute javascript in this way don't seem to do anything.

By now the executeJS mehod looks exactly like this:

	public void executeJS(final String javascript) {
		try {
			Runnable jsr = new Runnable() {
				public void run() {
					mdBrowserField.displayContent((javascript + ";var stupidVariableThatsNeededToGetAnotherHash = \"" + getUUID() + "\";").getBytes(),
							"text/javascript", "javascript:" + javascript + ";var stupidVariableThatsNeededToGetAnotherHash = \"" + getUUID() + "\";");
					try {
						Thread.currentThread().join();
					} catch (Throwable e) {
						e.printStackTrace();
					}
				}
			};
			Thread jsrThread = new Thread(jsr);
			jsrThread.start();
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

	public static String getUUID() {
		int deviceID = DeviceInfo.getDeviceId();
		UUID u = new UUID(deviceID);
		String uuid = u.toString();

		return uuid + "-" + Integer.toString(UIDGenerator.getUID()).substring(4, 8) + "-" + Integer.toString(UIDGenerator.getUID()).substring(4, 8) + "-"
				+ Integer.toString(UIDGenerator.getUID()).substring(3, 7) + "-" + Long.toString(System.currentTimeMillis()).substring(0, 12);
	}

well, I just noticed that I've got 2 different guids per call, but that shouldnt be a problem either, thats just to make sure its not the BrowserFields caching mechanism (if it has one built in) that prevents it from loading the same javascript again.

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: ScriptException: No detail message

Sounds like you're making good progress and are almost there. Are you logging the JavaScript each time you generate it so that you can check that the result is valid JS? Not quite clear of how you're doing this end to end but I see escaping here and there and suspect it would be very easy to accidently create an invalid JS fragment that will not work. 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
My Carrier: none

Re: ScriptException: No detail message

No, I am not logging, but on the other hand its always just 1 escape and rather static, so I feel pretty confident to get that right by now :smileywink:

However, I still need to find out why the script is executed only once, it cant be because of caching, since theres a semi random value in the code, as well as in the origin.

 

What do you mean by end to end in this case?

Please use plain text.
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
My Carrier: none

Re: ScriptException: No detail message

I found out something funny: if I just call BrowserField.executeScript("alert(\"test\")") it actually works, while it still doesn't work when I call the function ive defined. My guess is that the ScriptEngine used by executeScript is not the same as the one my already running javascript is running in. Of course that still doesnt explain why the code is loaded only once through displayContent(), because its definitely called more often it just doesnt seem to have any impact on the Browserfield afterwards.

Please use plain text.
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
My Carrier: none

Re: ScriptException: No detail message

As it turns out, BrowserField.executeJavascript works just fine, as long as you call the function you want to be executed via "parent.functionYouWantToBeExecuted()", luckily the "parent." part is missing in every Documentation, you might want to change that.

Please use plain text.