Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(bidi): add support for emulation.setNetworkConditions (#39456)

Holger Benl96abd28f3403
diff --git a/packages/playwright-core/src/server/bidi/bidiBrowser.ts b/packages/playwright-core/src/server/bidi/bidiBrowser.ts
index 22e30f0901..e7ac1fc318 100644
--- a/packages/playwright-core/src/server/bidi/bidiBrowser.ts
+++ b/packages/playwright-core/src/server/bidi/bidiBrowser.ts
@@ -247,6 +247,8 @@ export class BidiBrowserContext extends BrowserContext {
promises.push(this.doUpdateExtraHTTPHeaders());
if (this._options.permissions)
promises.push(this.doGrantPermissions('*', this._options.permissions));
+ if (this._options.offline)
+ promises.push(this.doUpdateOffline());
await Promise.all(promises);
}
@@ -380,6 +382,10 @@ export class BidiBrowserContext extends BrowserContext {
}
async doUpdateOffline(): Promise<void> {
+ await this._browser._browserSession.send('emulation.setNetworkConditions', {
+ networkConditions: this._options.offline ? { type: 'offline' } : null,
+ userContexts: [this._userContextId()],
+ });
}
async doSetHTTPCredentials(httpCredentials?: types.Credentials): Promise<void> {
diff --git a/packages/playwright-core/src/server/bidi/third_party/bidiCommands.d.ts b/packages/playwright-core/src/server/bidi/third_party/bidiCommands.d.ts
index 1edc8868af..d0b80cf2cc 100644
--- a/packages/playwright-core/src/server/bidi/third_party/bidiCommands.d.ts
+++ b/packages/playwright-core/src/server/bidi/third_party/bidiCommands.d.ts
@@ -142,6 +142,10 @@ export interface Commands {
params: Bidi.Emulation.SetLocaleOverrideParameters;
returnType: Bidi.EmptyResult;
};
+ 'emulation.setNetworkConditions': {
+ params: Bidi.Emulation.SetNetworkConditionsParameters;
+ returnType: Bidi.Emulation.SetNetworkConditionsResult;
+ };
'permissions.setPermission': {
params: Bidi.Permissions.SetPermissionParameters;
diff --git a/tests/bidi/expectations/moz-firefox-nightly-library.txt b/tests/bidi/expectations/moz-firefox-nightly-library.txt
index e0280875e0..9a83524456 100644
--- a/tests/bidi/expectations/moz-firefox-nightly-library.txt
+++ b/tests/bidi/expectations/moz-firefox-nightly-library.txt
@@ -5,9 +5,6 @@ library/browsercontext-basic.spec.ts › should close all belonging pages once c
library/browsercontext-basic.spec.ts › should disable javascript [fail]
library/browsercontext-basic.spec.ts › should emulate media in cross-process iframe [fail]
library/browsercontext-basic.spec.ts › should emulate media in popup [fail]
-library/browsercontext-basic.spec.ts › should emulate navigator.onLine [fail]
-library/browsercontext-basic.spec.ts › should emulate offline event [fail]
-library/browsercontext-basic.spec.ts › should work with offline option [fail]
library/browsercontext-cookies-third-party.spec.ts › same origin third party 'Partitioned;' cookie with different origin intermediate iframe [fail]
library/browsercontext-cookies-third-party.spec.ts › save/load third party non-partitioned cookies [fail]
library/browsercontext-cookies-third-party.spec.ts › save/load third party 'Partitioned;' cookies [fail]
@@ -57,11 +54,13 @@ library/browsercontext-viewport.spec.ts › should drag with high dpi [fail]
library/browsercontext-viewport.spec.ts › should support touch with null viewport [fail]
library/browsertype-connect.spec.ts › launchServer › should be able to connect 20 times to a single server without warnings [timeout]
library/browsertype-connect.spec.ts › launchServer › should save download [fail]
+library/browsertype-connect.spec.ts › launchServer › should save videos to artifactsDir [fail]
library/browsertype-connect.spec.ts › launchServer › should saveAs videos from remote browser [timeout]
library/browsertype-connect.spec.ts › launchServer › should upload a folder [fail]
library/browsertype-connect.spec.ts › run-server › should be able to connect 20 times to a single server without warnings [timeout]
library/browsertype-connect.spec.ts › run-server › should save download [fail]
library/browsertype-connect.spec.ts › run-server › should saveAs videos from remote browser [timeout]
+library/browsertype-connect.spec.ts › run-server › should save videos to artifactsDir [fail]
library/browsertype-connect.spec.ts › run-server › should upload a folder [fail]
library/browsertype-launch.spec.ts › should reject if launched browser fails immediately [fail]
library/capabilities.spec.ts › should play video @smoke [timeout]
@@ -135,6 +134,7 @@ library/inspector/cli-codegen-3.spec.ts › cli codegen › should generate fram
library/launcher.spec.ts › should throw a friendly error if its headed and there is no xserver on linux running [fail]
library/locator-dispatchevent-touch.spec.ts › should support touch points in touch event arguments [fail]
library/multiclient.spec.ts › last emulateMedia wins [fail]
+library/multiclient.spec.ts › should unroute websockets [timeout]
library/page-clock.spec.ts › popup › should tick after popup [flaky]
library/page-event-crash.spec.ts › should be able to close context when page crashes [timeout]
library/page-event-crash.spec.ts › should cancel navigation when page crashes [timeout]
@@ -149,13 +149,13 @@ library/permissions.spec.ts › permissions › should trigger permission onchan
library/permissions.spec.ts › should support clipboard read [fail]
library/popup.spec.ts › BrowserContext.addInitScript should apply to a cross-process popup [flaky]
library/popup.spec.ts › should expose function from browser context [fail]
-library/popup.spec.ts › should inherit offline from browser context [fail]
library/popup.spec.ts › should inherit touch support from browser context [fail]
library/popup.spec.ts › should not dispatch binding on a closed page [fail]
library/popup.spec.ts › should not throw when click closes popup [timeout]
library/popup.spec.ts › should use viewport size from window features [timeout]
library/role-utils.spec.ts › axe-core accessible-text [timeout]
library/role-utils.spec.ts › wpt accname #2 [timeout]
+library/route-web-socket.spec.ts › should emit close upon frame detach [timeout]
library/screenshot.spec.ts › page screenshot › should work with device scale factor and scale:css [fail]
library/screenshot.spec.ts › page screenshot › should work with device scale factor, clip and scale:css [fail]
library/selector-generator.spec.ts › selector generator › should work in dynamic iframes without navigation [fail]
@@ -178,6 +178,7 @@ library/trace-viewer.spec.ts › should highlight locator in iframe while typing
library/trace-viewer.spec.ts › should open console errors on click [fail]
library/trace-viewer.spec.ts › should pick locator in iframe [fail]
library/trace-viewer.spec.ts › should render console [fail]
+library/trace-viewer.spec.ts › should show only one pointer with multilevel iframes [fail]
library/tracing.spec.ts › should collect trace with resources, but no js [fail]
library/tracing.spec.ts › should produce screencast frames crop [fail]
library/tracing.spec.ts › should produce screencast frames fit [fail]
diff --git a/tests/bidi/expectations/moz-firefox-nightly-page.txt b/tests/bidi/expectations/moz-firefox-nightly-page.txt
index dc96e4a411..12038eb0e8 100644
--- a/tests/bidi/expectations/moz-firefox-nightly-page.txt
+++ b/tests/bidi/expectations/moz-firefox-nightly-page.txt
@@ -13,6 +13,8 @@ page/elementhandle-scroll-into-view.spec.ts › should work @smoke [fail]
page/expect-misc.spec.ts › strict mode violation error format [fail]
page/frame-evaluate.spec.ts › should allow cross-frame element handles [fail]
page/frame-evaluate.spec.ts › should not allow cross-frame element handles when frames do not script each other [fail]
+page/frame-evaluate.spec.ts › should dispose context on cross-origin navigation [fail]
+page/frame-evaluate.spec.ts › should dispose context on navigation [fail]
page/frame-goto.spec.ts › should continue after client redirect [flaky]
page/frame-hierarchy.spec.ts › should support framesets [fail]
page/interception.spec.ts › should disable memory cache when intercepting [timeout]
@@ -54,6 +56,7 @@ page/page-accessibility.spec.ts › should work when there is a title [fail]
page/page-accessibility.spec.ts › should work with aria-invalid accessibility tree [fail]
page/page-accessibility.spec.ts › should work with regular text [fail]
page/page-add-init-script.spec.ts › init script should run only once in popup [timeout]
+page/page-add-init-script.spec.ts › init script should run only once in iframe [fail]
page/page-add-script-tag.spec.ts › should throw when added with content to the CSP page [fail]
page/page-add-style-tag.spec.ts › should throw when added with content to the CSP page [timeout]
page/page-aria-snapshot-ai.spec.ts › return empty snapshot when iframe is not loaded [flaky]