chore: fix bidi reload (#10911)
This commit is contained in:
parent
3c659e7170
commit
e8640fff16
@ -245,8 +245,7 @@ export class BidiBrowser extends Browser {
|
||||
if (this.#connection.closed) {
|
||||
return;
|
||||
}
|
||||
// TODO: implement browser.close.
|
||||
// await this.#connection.send('browser.close', {});
|
||||
await this.#connection.send('browser.close', {});
|
||||
this.#connection.dispose();
|
||||
await this.#closeCallback?.call(null);
|
||||
}
|
||||
|
@ -236,21 +236,34 @@ export class BrowsingContext extends Realm {
|
||||
}
|
||||
}
|
||||
|
||||
async reload(options: WaitForOptions & {timeout: number}): Promise<void> {
|
||||
async reload(
|
||||
options: WaitForOptions & {timeout: number}
|
||||
): Promise<string | null> {
|
||||
const {waitUntil = 'load', timeout} = options;
|
||||
|
||||
const readinessState = lifeCycleToReadinessState.get(
|
||||
getWaitUntilSingle(waitUntil)
|
||||
) as Bidi.BrowsingContext.ReadinessState;
|
||||
|
||||
await waitWithTimeout(
|
||||
this.connection.send('browsingContext.reload', {
|
||||
context: this.#id,
|
||||
wait: readinessState,
|
||||
}),
|
||||
'Navigation',
|
||||
timeout
|
||||
);
|
||||
try {
|
||||
const {result} = await waitWithTimeout(
|
||||
this.connection.send('browsingContext.reload', {
|
||||
context: this.#id,
|
||||
wait: readinessState,
|
||||
}),
|
||||
'Navigation',
|
||||
timeout
|
||||
);
|
||||
|
||||
return result.navigation;
|
||||
} catch (error) {
|
||||
if (error instanceof ProtocolError) {
|
||||
error.message += ` at ${this.url}`;
|
||||
} else if (error instanceof TimeoutError) {
|
||||
error.message = 'Navigation timeout of ' + timeout + ' ms exceeded';
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async setContent(
|
||||
|
@ -52,6 +52,11 @@ interface Commands {
|
||||
returnType: Bidi.EmptyResult;
|
||||
};
|
||||
|
||||
'browser.close': {
|
||||
params: Bidi.EmptyParams;
|
||||
returnType: Bidi.EmptyResult;
|
||||
};
|
||||
|
||||
'browsingContext.activate': {
|
||||
params: Bidi.BrowsingContext.ActivateParameters;
|
||||
returnType: Bidi.EmptyResult;
|
||||
@ -74,7 +79,7 @@ interface Commands {
|
||||
};
|
||||
'browsingContext.reload': {
|
||||
params: Bidi.BrowsingContext.ReloadParameters;
|
||||
returnType: Bidi.EmptyResult;
|
||||
returnType: Bidi.BrowsingContext.NavigateResult;
|
||||
};
|
||||
'browsingContext.print': {
|
||||
params: Bidi.BrowsingContext.PrintParameters;
|
||||
@ -281,6 +286,7 @@ export class BidiConnection extends EventEmitter<BidiEvents> {
|
||||
this.#closed = true;
|
||||
this.#transport.onmessage = undefined;
|
||||
this.#transport.onclose = undefined;
|
||||
|
||||
this.#callbacks.clear();
|
||||
}
|
||||
|
||||
|
@ -410,23 +410,13 @@ export class BidiPage extends Page {
|
||||
override async reload(
|
||||
options?: WaitForOptions
|
||||
): Promise<BidiHTTPResponse | null> {
|
||||
const [response] = await Promise.all([
|
||||
this.waitForResponse(response => {
|
||||
return (
|
||||
response.request().isNavigationRequest() &&
|
||||
response.url() === this.url()
|
||||
);
|
||||
}),
|
||||
this.mainFrame()
|
||||
.context()
|
||||
.reload({
|
||||
...options,
|
||||
timeout:
|
||||
options?.timeout ?? this.#timeoutSettings.navigationTimeout(),
|
||||
}),
|
||||
]);
|
||||
|
||||
return response;
|
||||
const navigationId = await this.mainFrame()
|
||||
.context()
|
||||
.reload({
|
||||
...options,
|
||||
timeout: options?.timeout ?? this.#timeoutSettings.navigationTimeout(),
|
||||
});
|
||||
return this.getNavigationResponse(navigationId);
|
||||
}
|
||||
|
||||
override setDefaultNavigationTimeout(timeout: number): void {
|
||||
@ -494,8 +484,7 @@ export class BidiPage extends Page {
|
||||
await this.#cdpEmulationManager.emulateViewport(viewport);
|
||||
this.#viewport = viewport;
|
||||
if (needsReload) {
|
||||
// TODO: reload seems to hang in BiDi.
|
||||
// await this.reload();
|
||||
await this.reload();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,8 +231,9 @@ export const withSourcePuppeteerURLIfNone = <T extends NonNullable<unknown>>(
|
||||
}
|
||||
const original = Error.prepareStackTrace;
|
||||
Error.prepareStackTrace = (_, stack) => {
|
||||
// First element is the function. Second element is the caller of this
|
||||
// function. Third element is the caller of the caller of this function
|
||||
// First element is the function.
|
||||
// Second element is the caller of this function.
|
||||
// Third element is the caller of the caller of this function
|
||||
// which is precisely what we want.
|
||||
return stack[2];
|
||||
};
|
||||
|
@ -1863,7 +1863,7 @@
|
||||
"testIdPattern": "[emulation.spec] Emulation Page.viewport should detect touch when applying viewport with touches",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["FAIL"]
|
||||
"expectations": ["PASS"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[emulation.spec] Emulation Page.viewport should get the proper viewport size",
|
||||
@ -1881,7 +1881,7 @@
|
||||
"testIdPattern": "[emulation.spec] Emulation Page.viewport should support touch emulation",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["FAIL"]
|
||||
"expectations": ["PASS"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[evaluation.spec] Evaluation specs \"after each\" hook for \"should transfer 100Mb of data from page to node.js\"",
|
||||
|
Loading…
Reference in New Issue
Block a user