polkawallet-io / sdk

polkawallet SDK for integrating substrate-based blockchain as a plugin.
Apache License 2.0
18 stars 24 forks source link

Domain=WKErrorDomain Code=4 "发生JavaScript异常" #41

Closed chenyoh closed 8 months ago

chenyoh commented 8 months ago

Describe the bug When I use the assets/index.js in our iOS project, I will report the following error when I use WKWebView to inject the index.js in the iOS project Domain=WKErrorDomain Code=4 "发生JavaScript异常" UserInfo={WKJavaScriptExceptionLineNumber=2, WKJavaScriptExceptionMessage=SecurityError: The operation is insecure., WKJavaScriptExceptionColumnNumber=3621727, WKJavaScriptExceptionSourceURL=about:blank, NSLocalizedDescription=发生JavaScript异常}

This is the solution I found on the Internet but it doesn't work https://stackoverflow.com/questions/54061707/how-to-set-localstorage-item-in-webview-before-loading-a-urlrequest

Can IOS solve this problem?

Smartphone (please complete the following information):

RomeroYang commented 8 months ago

try ios 16.x

chenyoh commented 8 months ago

try ios 16.x

I used a 16.5 iPhone 11 pro max, but the problem still occurred Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=2, WKJavaScriptExceptionMessage=SecurityError: The operation is insecure., WKJavaScriptExceptionColumnNumber=3614803, WKJavaScriptExceptionSourceURL=about:blank, NSLocalizedDescription=A JavaScript exception occurred}

But the same index.js will work fine on Android

Here's my code 截屏2024-03-04 14 02 26

RomeroYang commented 8 months ago

this may caused by android security policy, you can't operate cookies or localstorage in about:blank page. the polkawallet flutter sdk run the js file in https://github.com/polkawallet-io/sdk/blob/e3aeb2208c66500d90cf4588131ac7f2effff345/lib/service/webViewRunner.dart#L74 to avoid this issue.

chenyoh commented 8 months ago

this may caused by android security policy, you can't operate cookies or localstorage in about:blank page. the polkawallet flutter sdk run the js file in

https://github.com/polkawallet-io/sdk/blob/e3aeb2208c66500d90cf4588131ac7f2effff345/lib/service/webViewRunner.dart#L74

to avoid this issue.

That solves my problem. Thank you