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

Form表单问题 #15

Closed
dhui68 opened this issue Jun 3, 2020 · 8 comments
Closed

Form表单问题 #15

dhui68 opened this issue Jun 3, 2020 · 8 comments
Labels
help wanted Extra attention is needed tip tip for help coding

Comments

@dhui68
Copy link

dhui68 commented Jun 3, 2020

页面中含有

标签这种情况,通过form.submit()或者form.onsubmit()提交表单,不会hook拦截

@dhui68
Copy link
Author

dhui68 commented Jun 3, 2020

NSURLProtocol 拦截处理wkwebview的请求,导致网页中的post请求httpbody,httpbodystream 是空的,才找到你的这个hook方式,但是发现有bug,能处理ajax方式的post请求,但是不能处理form表单的form.submit这种提交,求解决

@karosLi
Copy link
Owner

karosLi commented Jun 11, 2020

form表单form.submit走的不是ajax,ajax hook拦截不到。
有两种方式你可以考虑:
1、替换表单的提交为ajax形式
2、增加黑名单机制,针对这类链接不要使用离线包机制

@linwkr
Copy link

linwkr commented Jun 15, 2020

@karosLi 2、增加黑名单机制,针对这类链接不要使用离线包机制
问一下这句什么意思?
使用registerSchemeForCustomProtocol方法,并注册NSURLProtocol子类,来加载本地缓存文件。这个应该是整个APP的行为。怎么通过黑名单,来禁止一些链接使用离线包呢

@karosLi
Copy link
Owner

karosLi commented Jun 16, 2020

类似于这样,有一个统一的方法可以开启和关闭离线包功能。是否关闭的逻辑,你可以通过服务器端后台下发一些H5链接的黑名单列表,然后再下面几个入口做判断是否需要关闭离线包功能。

  • 首次同步请求
  • 链接跳转之前 (decidePolicyForNavigationAction)
- (void)enableOffineH5:(BOOL)enable {
    if (enable) {
        _jsBridgeEngine.config.enableAjaxHook = YES;
        [NSURLProtocol wkWebView_registerScheme:@"http"];
        [NSURLProtocol wkWebView_registerScheme:@"https"];
    } else {
        _jsBridgeEngine.config.enableAjaxHook = NO;
        [NSURLProtocol wkWebView_unregisterScheme:@"http"];
        [NSURLProtocol wkWebView_unregisterScheme:@"https"];
    }
}

@linwkr
Copy link

linwkr commented Jun 16, 2020

@karosLi decidePolicyForNavigationAction里做开关,不会发生两个webview同时加载,一个开启缓存,一个不需要缓存,发生需要缓存的资源,请求没有发到本地吗?

@karosLi
Copy link
Owner

karosLi commented Jun 16, 2020

一般的话还是一个webview在加载,你要是有两个webview同时加载加载场景,那就不行。
不过最好还是建议替换表单的提交为ajax形式,避免开关的维护。

@linwkr
Copy link

linwkr commented Jun 16, 2020

一般的话还是一个webview在加载,你要是有两个webview同时加载加载场景,那就不行。
不过最好还是建议替换表单的提交为ajax形式,避免开关的维护。

大概明白了。谢谢解答

@karosLi
Copy link
Owner

karosLi commented Jun 21, 2020

新的版本 KKJSBridge 1.1.1

可以通过 form.submit() 提交表单了

@karosLi karosLi closed this as completed Jun 21, 2020
@karosLi karosLi added help wanted Extra attention is needed tip tip for help coding labels Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed tip tip for help coding
Projects
None yet
Development

No branches or pull requests

3 participants