I use WKWebview.evaluateJavaScript() to execute javascript, I can get string, object and array from javascript.
evaluateJavaScript("document.getElementById('title').innerHTML;")
/*
output:
Optional(hhhhhhhhhhhhhh)
*/
evaluateJavaScript("[1,2];")
/*
output:
Optional(<__NSArrayM 0x17005faa0>(
1,
2
)
*/
evaluateJavaScript("{a:1, b:2};")
/*
output:
Optional({
a = 1;
b = 2;
})
*/
While I execute this code
evaluateJavaScript("document.getElementById('test').getBoundingClientRect();")
//an object of { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 }
I get this error,
Optional(Error Domain=WKErrorDomain Code=5 "execute JavaScript unsupported return type" UserInfo={NSLocalizedDescription=execute JavaScript unsupported return type}) nil
Any help will appreciated, thank you.
I think here the result of
document.getElementById('liveMovie').getBoundingClientRect();
is not support by swift.So I change it to an array, like this,