Skip to content

Commit

Permalink
chore: add Page.reload for BiDi (#10274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed May 31, 2023
1 parent 3fdad21 commit 6f8ea57
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 17 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"test:chrome:new-headless": "wireit",
"test:chrome:headless": "wireit",
"test:chrome:bidi": "wireit",
"test:chrome:bidi-local": "wireit",
"test:chrome": "wireit",
"test:firefox:bidi": "wireit",
"test:firefox:headful": "wireit",
Expand Down Expand Up @@ -81,6 +82,12 @@
"./test:build"
]
},
"test:chrome:bidi-local": {
"command": "PUPPETEER_EXECUTABLE_PATH=$(node tools/download_chrome_bidi.mjs ~/.cache/puppeteer/chrome-canary --shell) npm test -- --test-suite chrome-bidi",
"dependencies": [
"./test:build"
]
},
"test:firefox:headful": {
"command": "npm test -- --test-suite firefox-headful",
"dependencies": [
Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"author": "The Chromium Authors",
"license": "Apache-2.0",
"dependencies": {
"chromium-bidi": "0.4.10",
"chromium-bidi": "0.4.11",
"cross-fetch": "3.1.6",
"debug": "4.3.4",
"devtools-protocol": "0.0.1120988",
Expand Down
21 changes: 21 additions & 0 deletions packages/puppeteer-core/src/common/bidi/BrowsingContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
import ProtocolMapping from 'devtools-protocol/types/protocol-mapping.js';

import {WaitForOptions} from '../../api/Page.js';
import {assert} from '../../util/assert.js';
import {stringifyFunction} from '../../util/Function.js';
import {ProtocolError, TimeoutError} from '../Errors.js';
Expand Down Expand Up @@ -116,6 +117,26 @@ export class BrowsingContext extends EventEmitter {
}
}

async reload(options: WaitForOptions = {}): Promise<void> {
const {
waitUntil = 'load',
timeout = this.#timeoutSettings.navigationTimeout(),
} = 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
);
}

async evaluateHandle<
Params extends unknown[],
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>
Expand Down
4 changes: 4 additions & 0 deletions packages/puppeteer-core/src/common/bidi/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ interface Commands {
params: Bidi.BrowsingContext.NavigateParameters;
returnType: Bidi.BrowsingContext.NavigateResult;
};
'browsingContext.reload': {
params: Bidi.BrowsingContext.ReloadParameters;
returnType: Bidi.Message.EmptyResult;
};
'browsingContext.print': {
params: Bidi.BrowsingContext.PrintParameters;
returnType: Bidi.BrowsingContext.PrintResult;
Expand Down
16 changes: 16 additions & 0 deletions packages/puppeteer-core/src/common/bidi/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,22 @@ export class Page extends PageBase {
return this.mainFrame().goto(url, options);
}

override async reload(
options?: WaitForOptions
): Promise<HTTPResponse | null> {
const [response] = await Promise.all([
this.waitForResponse(response => {
return (
response.request().isNavigationRequest() &&
response.url() === this.url()
);
}),
this.mainFrame().context().reload(options),
]);

return response;
}

override url(): string {
return this.mainFrame().url();
}
Expand Down
20 changes: 13 additions & 7 deletions test/TestExpectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,6 @@
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[navigation.spec] navigation Page.reload should work",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL", "TIMEOUT"]
},
{
"testIdPattern": "[network.spec] network Network Events Page.Events.RequestFinished",
"platforms": ["darwin", "linux", "win32"],
Expand Down Expand Up @@ -530,7 +524,7 @@
{
"testIdPattern": "[network.spec] network Response.fromCache should work",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
Expand Down Expand Up @@ -1379,6 +1373,12 @@
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[navigation.spec] navigation Page.goto should return last response in redirect chain",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[navigation.spec] navigation Page.goto should return response when page changes its URL after load",
"platforms": ["darwin", "linux", "win32"],
Expand Down Expand Up @@ -1457,6 +1457,12 @@
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"]
},
{
"testIdPattern": "[navigation.spec] navigation Page.reload should work",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[navigation.spec] navigation Page.waitForNavigation should work when subframe issues window.stop()",
"platforms": ["darwin", "linux", "win32"],
Expand Down
4 changes: 3 additions & 1 deletion tools/download_chrome_bidi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ try {
browser,
buildId,
});
actions.setOutput('executablePath', executablePath);
if (process.argv.indexOf('--shell') === -1) {
actions.setOutput('executablePath', executablePath);
}
console.log(executablePath);
} catch (err) {
actions.setFailed(`Failed to download the browser: ${err.message}`);
Expand Down

0 comments on commit 6f8ea57

Please sign in to comment.