mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: validate client/server version match for remote connections (#10542)
* chore: validate client/server version match on connect * only validate major and minor
This commit is contained in:
parent
90e7a45211
commit
41070a2f55
@ -40,6 +40,7 @@ import { Artifact } from './artifact';
|
||||
import { EventEmitter } from 'events';
|
||||
import { JsonPipe } from './jsonPipe';
|
||||
import { APIRequestContext } from './fetch';
|
||||
import { getPlaywrightVersion } from '../utils/utils';
|
||||
|
||||
class Root extends ChannelOwner<channels.RootChannel> {
|
||||
constructor(connection: Connection) {
|
||||
@ -49,6 +50,7 @@ class Root extends ChannelOwner<channels.RootChannel> {
|
||||
async initialize(): Promise<Playwright> {
|
||||
return Playwright.from((await this._channel.initialize({
|
||||
sdkLanguage: 'javascript',
|
||||
version: getPlaywrightVersion(),
|
||||
})).playwright);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import { EventEmitter } from 'events';
|
||||
import * as channels from '../protocol/channels';
|
||||
import { serializeError } from '../protocol/serializers';
|
||||
import { createScheme, Validator, ValidationError } from '../protocol/validator';
|
||||
import { assert, debugAssert, isUnderTest, monotonicTime } from '../utils/utils';
|
||||
import { assert, debugAssert, getPlaywrightVersion, isUnderTest, monotonicTime } from '../utils/utils';
|
||||
import { tOptional } from '../protocol/validatorPrimitives';
|
||||
import { kBrowserOrContextClosedError } from '../utils/errors';
|
||||
import { CallMetadata, SdkObject } from '../server/instrumentation';
|
||||
@ -132,6 +132,7 @@ export class Root extends Dispatcher<{ guid: '' }, any> {
|
||||
async initialize(params: channels.RootInitializeParams): Promise<channels.RootInitializeResult> {
|
||||
assert(this.createPlaywright);
|
||||
assert(!this._initialized);
|
||||
assertPlaywrightVersion(params.version);
|
||||
this._initialized = true;
|
||||
return {
|
||||
playwright: await this.createPlaywright(this, params),
|
||||
@ -320,3 +321,10 @@ function formatLogRecording(log: string[]): string {
|
||||
}
|
||||
|
||||
let lastEventId = 0;
|
||||
|
||||
function assertPlaywrightVersion(givenVersion: string): void {
|
||||
const expectedVersion = getPlaywrightVersion();
|
||||
const givenParts = givenVersion.split('.');
|
||||
const expectedParts = givenVersion.split('.');
|
||||
assert(givenParts.slice(0, 2).join('.') === expectedParts.slice(0, 2).join('.'), `${expectedVersion} does not match the client version ${givenVersion}.`);
|
||||
}
|
||||
|
@ -346,6 +346,7 @@ export interface RootChannel extends RootEventTarget, Channel {
|
||||
}
|
||||
export type RootInitializeParams = {
|
||||
sdkLanguage: string,
|
||||
version: string,
|
||||
};
|
||||
export type RootInitializeOptions = {
|
||||
|
||||
|
@ -415,6 +415,7 @@ Root:
|
||||
initialize:
|
||||
parameters:
|
||||
sdkLanguage: string
|
||||
version: string
|
||||
returns:
|
||||
playwright: Playwright
|
||||
|
||||
|
@ -188,6 +188,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||
scheme.LifecycleEvent = tEnum(['load', 'domcontentloaded', 'networkidle', 'commit']);
|
||||
scheme.RootInitializeParams = tObject({
|
||||
sdkLanguage: tString,
|
||||
version: tString,
|
||||
});
|
||||
scheme.PlaywrightSocksConnectedParams = tObject({
|
||||
uid: tString,
|
||||
|
Loading…
x
Reference in New Issue
Block a user