Skip to content

Commit 6bbe7eb

Browse files
authored
chore(rpc): inline options parameter in all rpc channels (#2842)
1 parent 8d111a8 commit 6bbe7eb

14 files changed

+249
-248
lines changed

src/rpc/channels.ts

Lines changed: 64 additions & 63 deletions
Large diffs are not rendered by default.

src/rpc/client/accessibility.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export class Accessibility {
2828

2929
snapshot(options: { interestingOnly?: boolean; root?: ElementHandle } = {}): Promise<types.SerializedAXNode | null> {
3030
const root = options.root ? options.root._elementChannel : undefined;
31-
return this._channel.accessibilitySnapshot({ options: { interestingOnly: options.interestingOnly, root } });
31+
return this._channel.accessibilitySnapshot({ interestingOnly: options.interestingOnly, root });
3232
}
3333
}

src/rpc/client/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class Browser extends ChannelOwner<BrowserChannel, BrowserInitializer> {
4848

4949
async newContext(options: types.BrowserContextOptions = {}): Promise<BrowserContext> {
5050
delete (options as any).logger;
51-
const context = BrowserContext.from(await this._channel.newContext({ options }));
51+
const context = BrowserContext.from(await this._channel.newContext(options));
5252
this._contexts.add(context);
5353
context._browser = this;
5454
return context;

src/rpc/client/browserContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class BrowserContext extends ChannelOwner<BrowserContextChannel, BrowserC
116116
}
117117

118118
async grantPermissions(permissions: string[], options?: { origin?: string }): Promise<void> {
119-
await this._channel.grantPermissions({ permissions, options });
119+
await this._channel.grantPermissions({ permissions, ...options });
120120
}
121121

122122
async clearPermissions(): Promise<void> {

src/rpc/client/browserType.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ export class BrowserType extends ChannelOwner<BrowserTypeChannel, BrowserTypeIni
3737

3838
async launch(options: types.LaunchOptions = {}): Promise<Browser> {
3939
delete (options as any).logger;
40-
return Browser.from(await this._channel.launch({ options }));
40+
return Browser.from(await this._channel.launch(options));
4141
}
4242

43-
async launchServer(options?: types.LaunchServerOptions): Promise<BrowserServer> {
43+
async launchServer(options: types.LaunchServerOptions = {}): Promise<BrowserServer> {
4444
delete (options as any).logger;
45-
return BrowserServer.from(await this._channel.launchServer({ options }));
45+
return BrowserServer.from(await this._channel.launchServer(options));
4646
}
4747

4848
async launchPersistentContext(userDataDir: string, options: types.LaunchOptions & types.BrowserContextOptions = {}): Promise<BrowserContext> {
4949
delete (options as any).logger;
50-
return BrowserContext.from(await this._channel.launchPersistentContext({ userDataDir, options }));
50+
return BrowserContext.from(await this._channel.launchPersistentContext({ userDataDir, ...options }));
5151
}
5252

5353
async connect(options: types.ConnectOptions): Promise<Browser> {
5454
delete (options as any).logger;
55-
return Browser.from(await this._channel.connect({ options }));
55+
return Browser.from(await this._channel.connect(options));
5656
}
5757
}

src/rpc/client/elementHandle.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,64 +68,64 @@ export class ElementHandle<T extends Node = Node> extends JSHandle<T> {
6868
await this._elementChannel.dispatchEvent({ type, eventInit });
6969
}
7070

71-
async scrollIntoViewIfNeeded(options?: types.TimeoutOptions) {
72-
await this._elementChannel.scrollIntoViewIfNeeded({ options });
71+
async scrollIntoViewIfNeeded(options: types.TimeoutOptions = {}) {
72+
await this._elementChannel.scrollIntoViewIfNeeded(options);
7373
}
7474

7575
async hover(options: types.PointerActionOptions & types.PointerActionWaitOptions = {}): Promise<void> {
76-
await this._elementChannel.hover({ options });
76+
await this._elementChannel.hover(options);
7777
}
7878

7979
async click(options: types.MouseClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions = {}): Promise<void> {
80-
return await this._elementChannel.click({ options });
80+
return await this._elementChannel.click(options);
8181
}
8282

8383
async dblclick(options: types.MouseMultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions = {}): Promise<void> {
84-
return await this._elementChannel.dblclick({ options });
84+
return await this._elementChannel.dblclick(options);
8585
}
8686

8787
async selectOption(values: string | ElementHandle | types.SelectOption | string[] | ElementHandle[] | types.SelectOption[] | null, options: types.NavigatingActionWaitOptions = {}): Promise<string[]> {
88-
return await this._elementChannel.selectOption({ values: convertSelectOptionValues(values), options });
88+
return await this._elementChannel.selectOption({ values: convertSelectOptionValues(values), ...options });
8989
}
9090

9191
async fill(value: string, options: types.NavigatingActionWaitOptions = {}): Promise<void> {
92-
return await this._elementChannel.fill({ value, options });
92+
return await this._elementChannel.fill({ value, ...options });
9393
}
9494

9595
async selectText(options: types.TimeoutOptions): Promise<void> {
96-
await this._elementChannel.selectText({ options });
96+
await this._elementChannel.selectText(options);
9797
}
9898

9999
async setInputFiles(files: string | types.FilePayload | string[] | types.FilePayload[], options: types.NavigatingActionWaitOptions = {}) {
100-
await this._elementChannel.setInputFiles({ files, options });
100+
await this._elementChannel.setInputFiles({ files, ...options });
101101
}
102102

103103
async focus(): Promise<void> {
104104
await this._elementChannel.focus();
105105
}
106106

107107
async type(text: string, options: { delay?: number } & types.NavigatingActionWaitOptions = {}): Promise<void> {
108-
await this._elementChannel.type({ text, options });
108+
await this._elementChannel.type({ text, ...options });
109109
}
110110

111111
async press(key: string, options: { delay?: number } & types.NavigatingActionWaitOptions = {}): Promise<void> {
112-
await this._elementChannel.press({ key, options });
112+
await this._elementChannel.press({ key, ...options });
113113
}
114114

115115
async check(options: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions = {}) {
116-
return await this._elementChannel.check({ options });
116+
return await this._elementChannel.check(options);
117117
}
118118

119119
async uncheck(options: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions = {}) {
120-
return await this._elementChannel.uncheck({ options });
120+
return await this._elementChannel.uncheck(options);
121121
}
122122

123123
async boundingBox(): Promise<types.Rect | null> {
124124
return await this._elementChannel.boundingBox();
125125
}
126126

127-
async screenshot(options?: types.ElementScreenshotOptions): Promise<Buffer> {
128-
return Buffer.from(await this._elementChannel.screenshot({ options }), 'base64');
127+
async screenshot(options: types.ElementScreenshotOptions = {}): Promise<Buffer> {
128+
return Buffer.from(await this._elementChannel.screenshot(options), 'base64');
129129
}
130130

131131
async $(selector: string): Promise<ElementHandle<Element> | null> {

src/rpc/client/frame.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ export class Frame extends ChannelOwner<FrameChannel, FrameInitializer> {
6060
}
6161

6262
async goto(url: string, options: GotoOptions = {}): Promise<network.Response | null> {
63-
return Response.fromNullable(await this._channel.goto({ url, options, isPage: this._page!._isPageCall }));
63+
return Response.fromNullable(await this._channel.goto({ url, ...options, isPage: this._page!._isPageCall }));
6464
}
6565

6666
async waitForNavigation(options: types.WaitForNavigationOptions = {}): Promise<network.Response | null> {
67-
return Response.fromNullable(await this._channel.waitForNavigation({ options, isPage: this._page!._isPageCall }));
67+
return Response.fromNullable(await this._channel.waitForNavigation({ ...options, isPage: this._page!._isPageCall }));
6868
}
6969

7070
async waitForLoadState(state: types.LifecycleEvent = 'load', options: types.TimeoutOptions = {}): Promise<void> {
71-
await this._channel.waitForLoadState({ state, options, isPage: this._page!._isPageCall });
71+
await this._channel.waitForLoadState({ state, ...options, isPage: this._page!._isPageCall });
7272
}
7373

7474
async frameElement(): Promise<ElementHandle> {
@@ -94,11 +94,11 @@ export class Frame extends ChannelOwner<FrameChannel, FrameInitializer> {
9494
}
9595

9696
async waitForSelector(selector: string, options: types.WaitForElementOptions = {}): Promise<ElementHandle<Element> | null> {
97-
return ElementHandle.fromNullable(await this._channel.waitForSelector({ selector, options, isPage: this._page!._isPageCall })) as ElementHandle<Element> | null;
97+
return ElementHandle.fromNullable(await this._channel.waitForSelector({ selector, ...options, isPage: this._page!._isPageCall })) as ElementHandle<Element> | null;
9898
}
9999

100100
async dispatchEvent(selector: string, type: string, eventInit?: any, options: types.TimeoutOptions = {}): Promise<void> {
101-
await this._channel.dispatchEvent({ selector, type, eventInit: serializeArgument(eventInit), options, isPage: this._page!._isPageCall });
101+
await this._channel.dispatchEvent({ selector, type, eventInit: serializeArgument(eventInit), ...options, isPage: this._page!._isPageCall });
102102
}
103103

104104
async $eval<R, Arg>(selector: string, pageFunction: FuncOn<Element, Arg, R>, arg: Arg): Promise<R>;
@@ -125,7 +125,7 @@ export class Frame extends ChannelOwner<FrameChannel, FrameInitializer> {
125125
}
126126

127127
async setContent(html: string, options: types.NavigateOptions = {}): Promise<void> {
128-
await this._channel.setContent({ html, options, isPage: this._page!._isPageCall });
128+
await this._channel.setContent({ html, ...options, isPage: this._page!._isPageCall });
129129
}
130130

131131
name(): string {
@@ -149,72 +149,72 @@ export class Frame extends ChannelOwner<FrameChannel, FrameInitializer> {
149149
}
150150

151151
async addScriptTag(options: { url?: string, path?: string, content?: string, type?: string }): Promise<ElementHandle> {
152-
return ElementHandle.from(await this._channel.addScriptTag({ options, isPage: this._page!._isPageCall }));
152+
return ElementHandle.from(await this._channel.addScriptTag({ ...options, isPage: this._page!._isPageCall }));
153153
}
154154

155155
async addStyleTag(options: { url?: string; path?: string; content?: string; }): Promise<ElementHandle> {
156-
return ElementHandle.from(await this._channel.addStyleTag({ options, isPage: this._page!._isPageCall }));
156+
return ElementHandle.from(await this._channel.addStyleTag({ ...options, isPage: this._page!._isPageCall }));
157157
}
158158

159159
async click(selector: string, options: types.MouseClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions = {}) {
160-
return await this._channel.click({ selector, options, isPage: this._page!._isPageCall });
160+
return await this._channel.click({ selector, ...options, isPage: this._page!._isPageCall });
161161
}
162162

163163
async dblclick(selector: string, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions = {}) {
164-
return await this._channel.dblclick({ selector, options, isPage: this._page!._isPageCall });
164+
return await this._channel.dblclick({ selector, ...options, isPage: this._page!._isPageCall });
165165
}
166166

167167
async fill(selector: string, value: string, options: types.NavigatingActionWaitOptions = {}) {
168-
return await this._channel.fill({ selector, value, options, isPage: this._page!._isPageCall });
168+
return await this._channel.fill({ selector, value, ...options, isPage: this._page!._isPageCall });
169169
}
170170

171171
async focus(selector: string, options: types.TimeoutOptions = {}) {
172-
await this._channel.focus({ selector, options, isPage: this._page!._isPageCall });
172+
await this._channel.focus({ selector, ...options, isPage: this._page!._isPageCall });
173173
}
174174

175175
async textContent(selector: string, options: types.TimeoutOptions = {}): Promise<null|string> {
176-
return await this._channel.textContent({ selector, options, isPage: this._page!._isPageCall });
176+
return await this._channel.textContent({ selector, ...options, isPage: this._page!._isPageCall });
177177
}
178178

179179
async innerText(selector: string, options: types.TimeoutOptions = {}): Promise<string> {
180-
return await this._channel.innerText({ selector, options, isPage: this._page!._isPageCall });
180+
return await this._channel.innerText({ selector, ...options, isPage: this._page!._isPageCall });
181181
}
182182

183183
async innerHTML(selector: string, options: types.TimeoutOptions = {}): Promise<string> {
184-
return await this._channel.innerHTML({ selector, options, isPage: this._page!._isPageCall });
184+
return await this._channel.innerHTML({ selector, ...options, isPage: this._page!._isPageCall });
185185
}
186186

187187
async getAttribute(selector: string, name: string, options: types.TimeoutOptions = {}): Promise<string | null> {
188-
return await this._channel.getAttribute({ selector, name, options, isPage: this._page!._isPageCall });
188+
return await this._channel.getAttribute({ selector, name, ...options, isPage: this._page!._isPageCall });
189189
}
190190

191191
async hover(selector: string, options: types.PointerActionOptions & types.PointerActionWaitOptions = {}) {
192-
await this._channel.hover({ selector, options, isPage: this._page!._isPageCall });
192+
await this._channel.hover({ selector, ...options, isPage: this._page!._isPageCall });
193193
}
194194

195195
async selectOption(selector: string, values: string | ElementHandle | types.SelectOption | string[] | ElementHandle[] | types.SelectOption[] | null, options: types.NavigatingActionWaitOptions = {}): Promise<string[]> {
196-
return await this._channel.selectOption({ selector, values: convertSelectOptionValues(values), options, isPage: this._page!._isPageCall });
196+
return await this._channel.selectOption({ selector, values: convertSelectOptionValues(values), ...options, isPage: this._page!._isPageCall });
197197
}
198198

199199
async setInputFiles(selector: string, files: string | types.FilePayload | string[] | types.FilePayload[], options: types.NavigatingActionWaitOptions = {}): Promise<void> {
200200
const filePayloads = await normalizeFilePayloads(files);
201-
await this._channel.setInputFiles({ selector, files: filePayloads.map(f => ({ name: f.name, mimeType: f.mimeType, buffer: f.buffer.toString('base64') })), options, isPage: this._page!._isPageCall });
201+
await this._channel.setInputFiles({ selector, files: filePayloads.map(f => ({ name: f.name, mimeType: f.mimeType, buffer: f.buffer.toString('base64') })), ...options, isPage: this._page!._isPageCall });
202202
}
203203

204204
async type(selector: string, text: string, options: { delay?: number } & types.NavigatingActionWaitOptions = {}) {
205-
await this._channel.type({ selector, text, options, isPage: this._page!._isPageCall });
205+
await this._channel.type({ selector, text, ...options, isPage: this._page!._isPageCall });
206206
}
207207

208208
async press(selector: string, key: string, options: { delay?: number } & types.NavigatingActionWaitOptions = {}) {
209-
await this._channel.press({ selector, key, options, isPage: this._page!._isPageCall });
209+
await this._channel.press({ selector, key, ...options, isPage: this._page!._isPageCall });
210210
}
211211

212212
async check(selector: string, options: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions = {}) {
213-
await this._channel.check({ selector, options, isPage: this._page!._isPageCall });
213+
await this._channel.check({ selector, ...options, isPage: this._page!._isPageCall });
214214
}
215215

216216
async uncheck(selector: string, options: types.PointerActionWaitOptions & types.NavigatingActionWaitOptions = {}) {
217-
await this._channel.uncheck({ selector, options, isPage: this._page!._isPageCall });
217+
await this._channel.uncheck({ selector, ...options, isPage: this._page!._isPageCall });
218218
}
219219

220220
async waitForTimeout(timeout: number) {
@@ -224,7 +224,7 @@ export class Frame extends ChannelOwner<FrameChannel, FrameInitializer> {
224224
async waitForFunction<R, Arg>(pageFunction: Func1<Arg, R>, arg: Arg, options?: types.WaitForFunctionOptions): Promise<SmartHandle<R>>;
225225
async waitForFunction<R>(pageFunction: Func1<void, R>, arg?: any, options?: types.WaitForFunctionOptions): Promise<SmartHandle<R>>;
226226
async waitForFunction<R, Arg>(pageFunction: Func1<Arg, R>, arg: Arg, options: types.WaitForFunctionOptions = {}): Promise<SmartHandle<R>> {
227-
return JSHandle.from(await this._channel.waitForFunction({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), options, isPage: this._page!._isPageCall })) as SmartHandle<R>;
227+
return JSHandle.from(await this._channel.waitForFunction({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), ...options, isPage: this._page!._isPageCall })) as SmartHandle<R>;
228228
}
229229

230230
async title(): Promise<string> {

src/rpc/client/input.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ export class Keyboard {
3838
}
3939

4040
async type(text: string, options: { delay?: number } = {}) {
41-
await this._channel.keyboardType({ text, options });
41+
await this._channel.keyboardType({ text, ...options });
4242
}
4343

4444
async press(key: string, options: { delay?: number } = {}) {
45-
await this._channel.keyboardPress({ key, options });
45+
await this._channel.keyboardPress({ key, ...options });
4646
}
4747
}
4848

@@ -54,19 +54,19 @@ export class Mouse {
5454
}
5555

5656
async move(x: number, y: number, options: { steps?: number } = {}) {
57-
await this._channel.mouseMove({ x, y, options });
57+
await this._channel.mouseMove({ x, y, ...options });
5858
}
5959

6060
async down(options: { button?: types.MouseButton, clickCount?: number } = {}) {
61-
await this._channel.mouseDown({ options });
61+
await this._channel.mouseDown({ ...options });
6262
}
6363

6464
async up(options: { button?: types.MouseButton, clickCount?: number } = {}) {
65-
await this._channel.mouseUp({ options });
65+
await this._channel.mouseUp(options);
6666
}
6767

6868
async click(x: number, y: number, options: { delay?: number, button?: types.MouseButton, clickCount?: number } = {}) {
69-
await this._channel.mouseClick({ x, y, options });
69+
await this._channel.mouseClick({ x, y, ...options });
7070
}
7171

7272
async dblclick(x: number, y: number, options: { delay?: number, button?: types.MouseButton } = {}) {

0 commit comments

Comments
 (0)