Skip to content

Commit

Permalink
fix: 修复iOS侧H5注入脚本中语法错误导致的执行逻辑错误问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
Hulk committed Apr 9, 2022
1 parent cd241e6 commit a9161fe
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ - (void)dispatchEvent:(PrismDispatchEvent)event withSender:(NSObject *)sender pa
else if (event == PrismDispatchEventWKWebViewInitWithFrame) {
WKWebView *webView = (WKWebView*)sender;
WKWebViewConfiguration *configuration = [params objectForKey:@"configuration"];
NSString *recordScript = @"!function(){\"use strict\";var e=new(function(){function e(){}return e.prototype.record=function(e){for(var t=this.getContent(e),n=[];e&&\"body\"!==e.nodeName.toLowerCase();){var i=e.nodeName.toLowerCase();if(e.id)i+=\"#\"+e.id;else{for(var r=e.className.split(\" \").filter((function(e,t,n){e.trim()})).join(\".\"),o=!(null===r||\"\"===r),s=e,c=1;s.previousElementSibling;)s=s.previousElementSibling,o&&s.className.split(\" \").filter((function(e,t,n){e.trim()})).join(\".\")===r&&(o=!1),c+=1;if(o)for(s=e;s.nextElementSibling;)if(s=s.nextElementSibling,o&&s.className.split(\" \").filter((function(e,t,n){e.trim()})).join(\".\")===r){o=!1;break}o?i+=\".\"+r:c>1&&(i+=\":nth-child(\"+c+\")\")}n.unshift(i),e=e.parentElement}return n.unshift(\"body\"),{instruct:n.join(\">\"),content:t}},e.prototype.getContent=function(e){return e.innerText?this.getText(e):e.getAttribute(\"src\")?e.getAttribute(\"src\"):e.querySelectorAll(\"img\")&&e.querySelectorAll(\"img\").length>0?this.getImgSrc(e):\"\"},e.prototype.getText=function(e){if(!(e.childNodes&&e.childNodes.length>0))return e.innerText||e.nodeValue;for(var t=0;t<e.childNodes.length;t++)if(e.childNodes[t].childNodes){var n=this.getText(e.childNodes[t]);if(n)return n}},e.prototype.getImgSrc=function(e){var t=e.querySelectorAll(\"img\");return t&&t[0]&&t[0].src},e}()),t=!1;document.addEventListener(\"touchmove\",(function(){!0!==t&&(t=!0)})),document.addEventListener(\"touchend\",(function(n){if(!0!==t){if(n.target)try{window.webkit.messageHandlers.prism_record_instruct&&window.webkit.messageHandlers.prism_record_instruct.postMessage(e.record(n.target))}catch(e){}}else t=!1}))}();";
NSString *recordScript = @"!function(){\"use strict\";var e=new(function(){function e(){}return e.prototype.record=function(e){for(var t=this.getContent(e),n=[];e&&\"body\"!==e.nodeName.toLowerCase();){var r=e.nodeName.toLowerCase();if(e.id)r+=\"#\"+e.id;else{for(var i=e.className.split(\" \").filter((function(e){return\"\"!==e.trim()})).join(\".\"),o=!(null===i||\"\"===i),s=e,c=1;s.previousElementSibling;)s=s.previousElementSibling,o&&s.className.split(\" \").filter((function(e){return\"\"!==e.trim()})).join(\".\")===i&&(o=!1),c+=1;if(o)for(s=e;s.nextElementSibling;)if(s=s.nextElementSibling,o&&s.className.split(\" \").filter((function(e){return\"\"!==e.trim()})).join(\".\")===i){o=!1;break}o?r+=\".\"+i:c>1&&(r+=\":nth-child(\"+c+\")\")}n.unshift(r),e=e.parentElement}return n.unshift(\"body\"),{instruct:n.join(\">\"),content:t}},e.prototype.getContent=function(e){return e.innerText?this.getText(e):e.getAttribute(\"src\")?e.getAttribute(\"src\"):e.querySelectorAll(\"img\")&&e.querySelectorAll(\"img\").length>0?this.getImgSrc(e):\"\"},e.prototype.getText=function(e){if(!(e.childNodes&&e.childNodes.length>0))return e.innerText||e.nodeValue;for(var t=0;t<e.childNodes.length;t++)if(e.childNodes[t].childNodes){var n=this.getText(e.childNodes[t]);if(n)return n}},e.prototype.getImgSrc=function(e){var t=e.querySelectorAll(\"img\");return t&&t[0]&&t[0].src},e}()),t=!1;document.addEventListener(\"touchmove\",(function(){!0!==t&&(t=!0)})),document.addEventListener(\"touchend\",(function(n){if(!0!==t){if(n.target)try{window.webkit.messageHandlers.prism_record_instruct&&window.webkit.messageHandlers.prism_record_instruct.postMessage(e.record(n.target))}catch(e){}}else t=!1}))}();";

[webView prism_autoDot_addCustomScript:recordScript withConfiguration:configuration];
NSString *scriptName = @"prism_record_instruct";
Expand Down

0 comments on commit a9161fe

Please sign in to comment.