通过WebView访问各种HTML Navigator属性
我的任务是“本地”实施3DS付款验证流。当然,我们将重定向用户,显示特定的HTML内容,拨打各种电话等。根据服务提供商的说法。 他们用于初始化3DS流程的API请求信息,例如:
browserip字符串客户端的IP。它可以是IPv4或IPv6。
根据IETF BCP47,Navigator_language字符串语言。得到这个 navigator.language html属性。
navigator_javaenabled字符串从中获取此值 navigator.javaenabled html属性。
navigator_jsenabled字符串'true'如果在 客户的浏览器。 'false'否则。
screen_colordepth字符串从screen.colordepth html获取此值 属性。
screen_height字符串从screen.height html属性获取此值。
screen_width字符串从screen.width html属性获取此值。
timezoneOffset字符串通过运行'new来获取此值 date()。getTimeZoneOffset();'在客户端的浏览器中。
用户词字符串必须包含HTTP用户代理标头值。
browseraccept字符串它必须包含HTTP接受标头值。
我知道我可能可以获取用户的IP,启用JS的IP,屏幕尺寸& Web视图设置中的用户代理字符串&设备的配置属性,但是如何访问所有其他字段?我找不到附加在Web视图或其设置上的导航对象。是否有一种本地方法来检索所有这些细节?
I'm tasked with implementing a 3DS payment verification flow “natively”. We will of course be redirecting users, showing specific HTML content, making various calls, etc. according to the service provider.
Their API for initializing the 3DS process requests information such as :
BrowserIP string The IP of the client. It can be IPv4 or IPv6.
Navigator_language string Language according to IETF BCP47. Get this
value from navigator.language HTML property.Navigator_javaEnabled string Get this value from
navigator.javaEnabled HTML property.Navigator_jsEnabled string 'true' if javascript is enabled in
client's browser. 'false' otherwise.Screen_colorDepth string Get this value from screen.colorDepth HTML
property.Screen_height string Get this value from screen.height HTML property.
Screen_width string Get this value from screen.width HTML property.
TimezoneOffset string Get this value by running 'new
Date().getTimezoneOffset();' in the client's browser.UserAgent string It must contain the HTTP user-agent header value.
BrowserAccept string It must contain the HTTP accept header value.
I know that I can probably get the user's IP, JS-enabled, screen dimensions & user-agent string from the web view's settings & the device's configuration properties, but how would I access all these other fields? I couldn't find a navigator object attached to the web view or its settings. Is there a native way for retrieving all these details?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,经过很多比赛,我弄清楚了!首先,我使用
androidView
composable:在其中创建了一个普通的WebView:在其中,我使用了
web Chromeclient
实例,而不是常规webViewclient
,因为我阅读了它使其提供的方法更容易(即OnjSalert())。接下来,我通过Web视图设置启用了JavaScript,最后添加了一个自定义JS接口,该界面将完成所有提取工作。这是PaymentsJsInterface类:
因此,通过使用
loadurl()
方法在WebView中运行自定义JS脚本来实现提取,并指定URL是JS脚本(因此javascript:<
/代码>在开始)。完成此操作后,您可以访问JavaScriptInterface方法(通过@JavaScriptInterface通过“ Android”(在我的情况下)(在我的情况下)'命名空间'。由于JS代码在WebView中运行,您现在可以访问各种HTML属性例如
navigator
一个。Alright after a lot of playing around I figured it out! First and foremost I created a normal WebView using the
AndroidView
composable:Within it, I used a
WebChromeClient
instance instead of a regularWebViewClient
since I read that it makes such things easier with its provided methods (i.e. onJsAlert()). Next up, I enabled javascript through the web view settings and finally added a custom JS Interface that will do all of the extraction work.Here's the PaymentsJSInterface class:
So the extraction is achieved by running a custom JS script inside the webview using the
loadUrl()
method and specifying that the URL is a JS script (hence thejavascript:
at the beginning). Once you do that, you can access the JavascriptInterface methods (that are annotated with @JavascriptInterface through the "ANDROID" (in my case) 'namespace'. Since the JS code is running within a webView, you now have access to various HTML attributes such as theNavigator
one. With that, I could extract the necessary info by calling my JSInterface's method with the necessary parameters!