Created
May 31, 2025 14:41
-
-
Save polarnik/631110bc3c7fde8cafbf42d9026ec447 to your computer and use it in GitHub Desktop.
defaultPageCompleteCheck.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return (function(waitTime) { | |
| try { | |
| console.log(`defaultPageCompleteCheck: waitTime ${waitTime}`); | |
| var end = window.performance.timing.loadEventEnd; | |
| console.log(`defaultPageCompleteCheck: end ${end}`); | |
| var start= window.performance.timing.navigationStart; | |
| console.log(`defaultPageCompleteCheck: start ${start}`); | |
| console.log(`defaultPageCompleteCheck: end > 0 : ${end > 0}`); | |
| console.log(`defaultPageCompleteCheck: end - start + waitTime : ${end - start + waitTime}`); | |
| console.log(`defaultPageCompleteCheck: performance.now() : ${performance.now()}`); | |
| console.log(`defaultPageCompleteCheck: return 1 : ${ (end > 0) && (performance.now() > end - start + waitTime) }`); | |
| let status = (end > 0) && (performance.now() > end - start + waitTime); | |
| if(status) { | |
| try { | |
| const entries = performance.getEntriesByType("navigation"); | |
| const entry = entries[0]; | |
| performance.measure( "0_start_end", { | |
| start: 0, | |
| duration: window.performance.timing.loadEventEnd - window.performance.timing.navigationStart, | |
| }); | |
| performance.measure( "0_startTime_loadEventEnd", { | |
| start: 0, | |
| duration: entry.loadEventEnd - entry.startTime, | |
| }); | |
| performance.mark( "0_start_end", { | |
| startTime: window.performance.timing.loadEventEnd - window.performance.timing.navigationStart, | |
| }); | |
| performance.mark( "0_startTime_loadEventEnd", { | |
| startTime: entry.loadEventEnd, | |
| }); | |
| let index = 1; | |
| performance.measure(`${index++}_startTime_redirectStart`, | |
| { | |
| start: entry.startTime, | |
| duration: entry.redirectStart - entry.startTime, | |
| } | |
| ); | |
| performance.measure(`${index++}_redirectStart_redirectEnd`, | |
| { | |
| start: entry.redirectStart, | |
| duration: entry.redirectEnd - entry.redirectStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_redirectEnd_workerStart`, | |
| { | |
| start: entry.redirectEnd, | |
| duration: entry.workerStart - entry.redirectEnd, | |
| } | |
| ); | |
| performance.measure(`${index++}_workerStart_fetchStart`, | |
| { | |
| start: entry.workerStart, | |
| duration: entry.fetchStart - entry.workerStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_fetchStart_domainLookupStart`, | |
| { | |
| start: entry.fetchStart, | |
| duration: entry.domainLookupStart - entry.fetchStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_domainLookupStart_domainLookupEnd`, | |
| { | |
| start: entry.domainLookupStart, | |
| duration: entry.domainLookupEnd - entry.domainLookupStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_domainLookupEnd_connectStart`, | |
| { | |
| start: entry.domainLookupEnd, | |
| duration: entry.connectStart - entry.domainLookupEnd, | |
| } | |
| ); | |
| performance.measure(`${index++}_connectStart_secureConnectionStart`, | |
| { | |
| start: entry.connectStart, | |
| duration: entry.secureConnectionStart - entry.connectStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_secureConnectionStart_connectEnd`, | |
| { | |
| start: entry.secureConnectionStart, | |
| duration: entry.connectEnd - entry.secureConnectionStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_connectStart_connectEnd`, | |
| { | |
| start: entry.connectStart, | |
| duration: entry.connectEnd - entry.connectStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_connectEnd_requestStart`, | |
| { | |
| start: entry.connectEnd, | |
| duration: entry.requestStart - entry.connectEnd, | |
| } | |
| ); | |
| performance.measure(`${index++}_requestStart_responseStart`, | |
| { | |
| start: entry.requestStart, | |
| duration: entry.responseStart - entry.requestStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_responseStart_finalResponseHeadersStart`, | |
| { | |
| start: entry.requestStart, | |
| duration: entry.finalResponseHeadersStart - entry.responseStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_finalResponseHeadersStart_responseEnd`, | |
| { | |
| start: entry.finalResponseHeadersStart, | |
| duration: entry.responseEnd - entry.finalResponseHeadersStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_responseStart_responseEnd`, | |
| { | |
| start: entry.responseStart, | |
| duration: entry.responseEnd - entry.responseStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_unloadEventStart_unloadEventEnd`, | |
| { | |
| start: entry.unloadEventStart, | |
| duration: entry.unloadEventEnd - entry.unloadEventStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_responseEnd_domInteractive`, | |
| { | |
| start: entry.responseEnd, | |
| duration: entry.domInteractive - entry.responseEnd, | |
| } | |
| ); | |
| performance.measure(`${index++}_domInteractive_domContentLoadedEventStart`, | |
| { | |
| start: entry.domInteractive, | |
| duration: entry.domContentLoadedEventStart - entry.domInteractive, | |
| } | |
| ); | |
| performance.measure(`${index++}_domContentLoadedEventStart_domContentLoadedEventEnd`, | |
| { | |
| start: entry.domContentLoadedEventStart, | |
| duration: entry.domContentLoadedEventEnd - entry.domContentLoadedEventStart, | |
| } | |
| ); | |
| performance.measure(`${index++}_domContentLoadedEventEnd_domComplete`, | |
| { | |
| start: entry.domContentLoadedEventEnd, | |
| duration: entry.domComplete - entry.domContentLoadedEventEnd, | |
| } | |
| ); | |
| performance.measure(`${index++}_domComplete_loadEventStart`, | |
| { | |
| start: entry.domComplete, | |
| duration: entry.loadEventStart - entry.domComplete, | |
| } | |
| ); | |
| performance.measure(`${index++}_loadEventStart_loadEventEnd`, | |
| { | |
| start: entry.loadEventStart, | |
| duration: entry.loadEventEnd - entry.loadEventStart, | |
| } | |
| ); | |
| const measures_my = []; | |
| const marks_my = []; | |
| if (window.performance && window.performance.getEntriesByType) { | |
| const myMarks = Array.prototype.slice.call( | |
| window.performance.getEntriesByType('mark') | |
| ); | |
| for (const mark of myMarks) { | |
| if (mark.detail && mark.detail.devtools) { | |
| continue; | |
| } else { | |
| marks_my.push({ | |
| name: mark.name, | |
| startTime: mark.startTime | |
| }); | |
| } | |
| } | |
| const myMeasures = Array.prototype.slice.call( | |
| window.performance.getEntriesByType('measure') | |
| ); | |
| for (const measure of myMeasures) { | |
| if (measure.detail && measure.detail.devtools) { | |
| continue; | |
| } else { | |
| measures_my.push({ | |
| name: measure.name, | |
| duration: measure.duration, | |
| startTime: measure.startTime | |
| }); | |
| } | |
| } | |
| } | |
| console.log(`defaultPageCompleteCheck: measures_my: \n${JSON.stringify(measures_my)}`) | |
| console.log(`defaultPageCompleteCheck: marks_my: \n${JSON.stringify(marks_my)}`) | |
| } catch (e) { | |
| console.log(`defaultPageCompleteCheck: exception: \n${JSON.stringify(e)}`) | |
| } | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| catch(e) { | |
| console.log(`defaultPageCompleteCheck: e : ${JSON.stringify(e)}`); | |
| console.log(`defaultPageCompleteCheck: return 2 : true`); | |
| return true; | |
| } | |
| })(arguments[arguments.length - 1]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment