Install quirk for webview

I have an application containing a webview. When the <!DOCTYPE html> not set on the HTML page, it causes unforeseen errors, because the fragments I execute are only compatible with HTML5 .

So, instead of writing <!DOCTYPE html> every time, can I just set the default quirk (quirk is the default HTML declaration that will be used if the HTML version of the page is not specified).

Therefore, if the declaration of the HTML page of the page is not specified, it will automatically be displayed in HTML5.

Any ideas on how to do this? Major browsers use this technique (including Chrome for Android) .

EDIT

I have over 500 such fragments using the built-in SVG , etc. -

 <svg width="300" height="200"> <polygon points="100,10 40,198 190,78 10,78 160,198" style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" /> </svg> 

These snippets do not work well on other versions of HTML. I have no problem writing <!DOCTYPE html> on every page, but I worry about my clients who can see, edit and modify my snippets or even create a new snippet .

I handed over my application to my friends for testing, and many of them complained that the fragments created by him did not work properly, and I think the same things could happen to my clients.

Please, help

+6
source share
1 answer

EDIT: Chrome for Android does not use WebView [ Source ]:

Does this mean that Chrome for Android uses WebView?

No, Chrome for Android is different from WebView. They are both based on the same code, including a common JavaScript engine and a rendering engine.

Thus, they added this functionality on top of the usual WebView behavior. What you want to accomplish is impossible.


I think the only way this would be possible (based on my searches) is to override the behavior of the WebView and do something like this:

  • Catch Your Estimated URL
  • Use HttpClient to HttpClient Page Content
  • Check availability <! DOCTYPE> tag and add if does not exist
  • Use WebView.loadDataWithBaseURL to render HTML in WebView and specify the base url obtained in step 1

Obviously, these are very hacks, and I can’t confirm if it works at all. Thus , by far the best solution is to specify <! DOCTYPE> tag on each page . If this requires checking fragments before downloading / allowing clients to create them, then so be it.

+1
source

Source: https://habr.com/ru/post/976184/


All Articles