chore: add bidi+ emulation command (#10087)
This commit is contained in:
parent
e4b57c279a
commit
dd8c229a4f
@ -80,6 +80,14 @@ interface Commands {
|
||||
params: Bidi.Session.SubscribeParameters;
|
||||
returnType: Bidi.Session.UnsubscribeResult;
|
||||
};
|
||||
'cdp.sendCommand': {
|
||||
params: Bidi.CDP.SendCommandParams;
|
||||
returnType: Bidi.CDP.SendCommandResult;
|
||||
};
|
||||
'cdp.getSession': {
|
||||
params: Bidi.CDP.GetSessionParams;
|
||||
returnType: Bidi.CDP.GetSessionResult;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ import {HTTPResponse} from '../../api/HTTPResponse.js';
|
||||
import {WaitForOptions} from '../../api/Page.js';
|
||||
import {assert} from '../../util/assert.js';
|
||||
import {stringifyFunction} from '../../util/Function.js';
|
||||
import {ProtocolMapping} from '../Connection.js';
|
||||
import {ProtocolError, TimeoutError} from '../Errors.js';
|
||||
import {EventEmitter} from '../EventEmitter.js';
|
||||
import {PuppeteerLifeCycleEvent} from '../LifecycleWatcher.js';
|
||||
@ -222,6 +223,22 @@ export class Context extends EventEmitter {
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
async sendCDPCommand(
|
||||
method: keyof ProtocolMapping.Commands,
|
||||
params: object = {}
|
||||
): Promise<unknown> {
|
||||
const session = await this.#connection.send('cdp.getSession', {
|
||||
context: this._contextId,
|
||||
});
|
||||
// TODO: remove any once chromium-bidi types are updated.
|
||||
const sessionId = (session.result as any).cdpSession;
|
||||
return await this.#connection.send('cdp.sendCommand', {
|
||||
cdpMethod: method,
|
||||
cdpParams: params,
|
||||
cdpSession: sessionId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@ import {isErrorLike} from '../../util/ErrorLike.js';
|
||||
import {ConsoleMessage, ConsoleMessageLocation} from '../ConsoleMessage.js';
|
||||
import {Handler} from '../EventEmitter.js';
|
||||
import {PDFOptions} from '../PDFOptions.js';
|
||||
import {Viewport} from '../PuppeteerViewport.js';
|
||||
import {EvaluateFunc, HandleFor} from '../types.js';
|
||||
import {debugError, waitWithTimeout} from '../util.js';
|
||||
|
||||
@ -45,6 +46,7 @@ export class Page extends PageBase {
|
||||
['browsingContext.load', this.#onLoad.bind(this)],
|
||||
['browsingContext.domContentLoaded', this.#onDOMLoad.bind(this)],
|
||||
]) as Map<Bidi.Session.SubscribeParametersEvent, Handler>;
|
||||
#viewport: Viewport | null = null;
|
||||
|
||||
constructor(context: Context) {
|
||||
super();
|
||||
@ -204,6 +206,29 @@ export class Page extends PageBase {
|
||||
});
|
||||
}
|
||||
|
||||
override async setViewport(viewport: Viewport): Promise<void> {
|
||||
// TODO: use BiDi commands when available.
|
||||
const mobile = false;
|
||||
const width = viewport.width;
|
||||
const height = viewport.height;
|
||||
const deviceScaleFactor = 1;
|
||||
const screenOrientation = {angle: 0, type: 'portraitPrimary'};
|
||||
|
||||
await this.#context.sendCDPCommand('Emulation.setDeviceMetricsOverride', {
|
||||
mobile,
|
||||
width,
|
||||
height,
|
||||
deviceScaleFactor,
|
||||
screenOrientation,
|
||||
});
|
||||
|
||||
this.#viewport = viewport;
|
||||
}
|
||||
|
||||
override viewport(): Viewport | null {
|
||||
return this.#viewport;
|
||||
}
|
||||
|
||||
override async pdf(options: PDFOptions = {}): Promise<Buffer> {
|
||||
const {path = undefined} = options;
|
||||
const {
|
||||
|
@ -419,6 +419,12 @@
|
||||
"parameters": ["cdp", "firefox"],
|
||||
"expectations": ["FAIL", "SKIP"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[screenshot.spec] Screenshots Page.screenshot *",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["FAIL"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[TargetManager.spec] *",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
@ -1949,6 +1955,12 @@
|
||||
"parameters": ["cdp", "firefox"],
|
||||
"expectations": ["FAIL"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[screenshot.spec] Screenshots Page.screenshot should return base64",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["PASS"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[screenshot.spec] Screenshots Page.screenshot should return base64",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
@ -1967,6 +1979,12 @@
|
||||
"parameters": ["cdp", "firefox"],
|
||||
"expectations": ["FAIL", "PASS"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[screenshot.spec] Screenshots Page.screenshot should work",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["chrome", "webDriverBiDi"],
|
||||
"expectations": ["PASS"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[screenshot.spec] Screenshots Page.screenshot should work",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
|
Loading…
Reference in New Issue
Block a user