Skip to content

Commit

Permalink
feat: support pageLoadStrategy in readState check
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Jun 19, 2024
1 parent c0d6cc3 commit 498a1d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/mixins/navigate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ function cancelPageLoad () {
}
}

/**
* Return if current readState can be handles as page load completes
* for the given page load strategy,
* @param {string} pageLoadStrategy
* @param {string} readyState
* @returns string
*/
function completeToLoadPage (pageLoadStrategy, readyState) {
if (pageLoadStrategy === 'eager') {
// this could include 'interactive', or 'complete'
return readyState !== 'loading';
}
return readyState === 'complete';
}

/**
* @this {import('../remote-debugger').RemoteDebugger}
* @param {timing.Timer|null|undefined} startPageLoadTimer
Expand Down Expand Up @@ -114,7 +129,7 @@ async function checkPageIsReady (timeoutMs) {
const readyState = await B.resolve(this.execute(readyCmd, true))
.timeout(timeoutMs ?? this.pageReadyTimeout);
log.debug(`Document readyState is '${readyState}'`);
return readyState === 'complete';
return completeToLoadPage(this.pageLoadStrategy, readyState);
} catch (err) {
if (!(err instanceof B.TimeoutError)) {
throw err;
Expand Down Expand Up @@ -187,6 +202,11 @@ async function navToUrl (url) {
// and start sending `document.readyState` requests until we either succeed or
// another event/timeout happens
onTargetProvisioned = async () => {
if (this.pageLoadStrategy === 'none') {
log.debug("none page load strategy");

Check failure on line 206 in lib/mixins/navigate.js

View workflow job for this annotation

GitHub Actions / test (22)

Strings must use singlequote

Check failure on line 206 in lib/mixins/navigate.js

View workflow job for this annotation

GitHub Actions / test (20)

Strings must use singlequote

Check failure on line 206 in lib/mixins/navigate.js

View workflow job for this annotation

GitHub Actions / test (18)

Strings must use singlequote
return

Check failure on line 207 in lib/mixins/navigate.js

View workflow job for this annotation

GitHub Actions / test (22)

Missing semicolon

Check failure on line 207 in lib/mixins/navigate.js

View workflow job for this annotation

GitHub Actions / test (20)

Missing semicolon

Check failure on line 207 in lib/mixins/navigate.js

View workflow job for this annotation

GitHub Actions / test (18)

Missing semicolon
};

while (isPageLoading) {
const pageReadyCheckStart = new timing.Timer().start();
try {
Expand Down
7 changes: 7 additions & 0 deletions lib/remote-debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ class RemoteDebugger extends EventEmitter {
navigationDelay;
/** @type {import('./rpc/rpc-client').default?} */
rpcClient;
/** @type {string} */
pageLoadStrategy;

// events
/** @type {string} */
static EVENT_PAGE_CHANGE;
/** @type {string} */
static EVENT_DISCONNECT;
/** @type {string} */
static EVENT_FRAMES_DETACHED;

// methods
/** @type {() => Promise<void>} */
Expand Down Expand Up @@ -126,6 +130,7 @@ class RemoteDebugger extends EventEmitter {
webInspectorMaxFrameLength,
socketChunkSize,
fullPageInitialization,
pageLoadStrategy = 'normal'
} = opts;

this.bundleId = bundleId;
Expand Down Expand Up @@ -155,6 +160,8 @@ class RemoteDebugger extends EventEmitter {

this.fullPageInitialization = fullPageInitialization;

this.pageLoadStrategy = pageLoadStrategy;

this._lock = new AsyncLock();
}

Expand Down

0 comments on commit 498a1d0

Please sign in to comment.