html – iOS WKWebView intercepts the same js twice

[ad_1]

iOS15.3, use WKURLSchemeHandler to intercept requests, here my custom scheme is xscheme. My html is like this:

<!DOCTYPE html>
<html lang="en">
   <head>
     <meta charset="UTF-8" />
     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <title>Document</title>
     <script src="https://4.js"></script>
</head>
   <body>
     <img src="xscheme://1.js?max=3&idx=1" />
     <img src="xscheme://2.js?max=3&idx=2" />
     <img src="xscheme://3.js?max=3&idx=3" />
   </body>
</html>

The js order I intercepted is:

1.js
2.js
3.js
4.js
1.js
2.js
3.js

I located that this problem occurs as long as the scrpit tag is added to the head.
The order I expect should be:

4.js
1.js
2.js
3.js

I try to add multiple script tags in the head, it will only repeat 2 times, not multiple times.

I add a new tag <script src="https://1.js"></script> to html when 1.js is intercepted for the first time, but as long as 4.js executes Once done, my tag <script src="https://1.js"></script> was removed.

Through this phenomenon, it seems that after the script tag of the head is executed, the entire html will be refreshed again.

iOS WKWebView intercepts the same js twice

iOS15.3, use WKURLSchemeHandler to intercept requests, here my custom scheme is xscheme. My html is like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://4.js"></script>
</head>
  <body>
    <img src="xscheme://1.js?max=3&idx=1" />
    <img src="xscheme://2.js?max=3&idx=2" />
    <img src="xscheme://3.js?max=3&idx=3" />
  </body>
</html>

The js order I intercepted is:

1.js
2.js
3.js
4.js
1.js
2.js
3.js

I located that this problem occurs as long as the scrpit tag is added to the head.
The order I expect should be:

4.js
1.js
2.js
3.js

I try to add multiple script tags in the head, it will only repeat 2 times, not multiple times.
I add a new tag <script src="https://1.js"></script> to html when I intercept 1.js for the first time. But as long as 4.js executes After that, my tag <script src="https://1.js"></script> was removed.

Through this phenomenon, it seems that after the script tag of the head is executed, the entire html will be refreshed again.

Then I continued to try, when I intercepted 1.js for the first time, I saved it first, waited for 0.5s, and then added a new tag to the html <script src="https://1.js">< /script>. At this time, I found that the order is what I want.

4.js
1.js
2.js
3.js

So now the problem is very clear, save the intercepted js first, and then execute the js when the script tag of the head is executed.
Or execute js after the entire webView is loaded.

[ad_2]

Source link

Leave a Reply

Your email address will not be published.