Skip to content

Commit 439e048

Browse files
authored
feat(rpc): migrate DeviceDescriptors payload to an array (#2981)
Currently it is an object with arbitrary keys - that makes it hard to have a protocol definition.
1 parent 4c8ba3e commit 439e048

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/rpc/channels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type PlaywrightInitializer = {
2929
firefox: BrowserTypeChannel,
3030
webkit: BrowserTypeChannel,
3131
electron?: ElectronChannel,
32-
deviceDescriptors: types.Devices,
32+
deviceDescriptors: { name: string, descriptor: types.DeviceDescriptor }[],
3333
selectors: SelectorsChannel,
3434
};
3535

src/rpc/client/playwright.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export class Playwright extends ChannelOwner<PlaywrightChannel, PlaywrightInitia
3535
this.webkit = BrowserType.from(initializer.webkit);
3636
if (initializer.electron)
3737
(this as any).electron = Electron.from(initializer.electron);
38-
this.devices = initializer.deviceDescriptors;
38+
this.devices = {};
39+
for (const { name, descriptor } of initializer.deviceDescriptors)
40+
this.devices[name] = descriptor;
3941
this.selectors = Selectors.from(initializer.selectors);
4042
}
4143
}

src/rpc/server/playwrightDispatcher.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import { ElectronDispatcher } from './electronDispatcher';
2525
export class PlaywrightDispatcher extends Dispatcher<Playwright, PlaywrightInitializer> implements PlaywrightChannel {
2626
constructor(scope: DispatcherScope, playwright: Playwright) {
2727
const electron = (playwright as any).electron as (Electron | undefined);
28+
const deviceDescriptors = Object.entries(playwright.devices)
29+
.map(([name, descriptor]) => ({ name, descriptor }));
2830
super(scope, playwright, 'playwright', {
2931
chromium: new BrowserTypeDispatcher(scope, playwright.chromium!),
3032
firefox: new BrowserTypeDispatcher(scope, playwright.firefox!),
3133
webkit: new BrowserTypeDispatcher(scope, playwright.webkit!),
3234
electron: electron ? new ElectronDispatcher(scope, electron) : undefined,
33-
deviceDescriptors: playwright.devices,
35+
deviceDescriptors,
3436
selectors: new SelectorsDispatcher(scope, playwright.selectors),
3537
}, false, 'playwright');
3638
}

0 commit comments

Comments
 (0)