(url, callback)
| 12626 | var inCors = false; |
| 12627 | var checkRemoveIntv; |
| 12628 | function requestFromIframe(url, callback){ |
| 12629 | if (location.protocol === 'https:' && !/^https:/.test(url)) { |
| 12630 | ruleParser.noValidContent(url); |
| 12631 | } |
| 12632 | url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url; |
| 12633 | let iframe = document.createElement('iframe'); |
| 12634 | iframe.name = 'pagetual-iframe'; |
| 12635 | iframe.width = '100%'; |
| 12636 | iframe.height = '1000'; |
| 12637 | iframe.frameBorder = '0'; |
| 12638 | if (ruleParser.curSiteRule.sandbox != false) { |
| 12639 | iframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms"; |
| 12640 | } |
| 12641 | iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;flex:0;opacity:0!important;pointer-events:none!important;position:fixed;top:0px;left:0px;z-index:-2147483647;'; |
| 12642 | let waitTime = 100, checkEval; |
| 12643 | ruleParser.runWait((_checkEval, _waitTime) => { |
| 12644 | if (_checkEval) { |
| 12645 | checkEval = _checkEval; |
| 12646 | } |
| 12647 | if (_waitTime) { |
| 12648 | waitTime = _waitTime; |
| 12649 | } |
| 12650 | }); |
| 12651 | if (checkRemoveIntv) clearInterval(checkRemoveIntv); |
| 12652 | checkRemoveIntv = setInterval(() => { |
| 12653 | if (!iframe || !getBody(document).contains(iframe)) { |
| 12654 | clearInterval(checkRemoveIntv); |
| 12655 | loadPageOver(); |
| 12656 | } |
| 12657 | }, 500); |
| 12658 | let loadedHandler = async e => { |
| 12659 | if (e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load') return; |
| 12660 | clearInterval(checkRemoveIntv); |
| 12661 | window.removeEventListener('message', loadedHandler, false); |
| 12662 | iframe.removeEventListener('load', loadedHandler, false); |
| 12663 | let doc; |
| 12664 | try { |
| 12665 | doc = iframe.contentDocument || iframe.contentWindow.document; |
| 12666 | doc.hasFocus = () => true; |
| 12667 | } catch(e) {} |
| 12668 | let pageEleTryTimes = 0; |
| 12669 | async function checkIframe() { |
| 12670 | if (urlChanged || isPause) { |
| 12671 | return callback(false, false); |
| 12672 | } |
| 12673 | try { |
| 12674 | doc = doc || iframe.contentDocument || iframe.contentWindow.document; |
| 12675 | if (checkEval && !await checkEval(doc)) { |
| 12676 | setTimeout(() => { |
| 12677 | checkIframe(); |
| 12678 | }, waitTime); |
| 12679 | return; |
| 12680 | } else { |
| 12681 | let preCode = ruleParser.curSiteRule.pagePre, eles = null; |
| 12682 | if (preCode) { |
| 12683 | try { |
| 12684 | let preResult; |
| 12685 | if (typeof preCode == 'function') { |
no test coverage detected