Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .claude/skills/playwright-dev/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Playwright uses a client-server architecture connected by a protocol layer. The
```
packages/protocol/src/
protocol.yml — RPC protocol definition (source of truth)
channels.d.ts — generated TypeScript channel interfaces
callMetadata.d.ts — call metadata types

packages/playwright-core/src/
client/ — public API objects (ChannelOwner subclasses)
channels.d.ts — generated client channel interfaces
server/ — browser automation implementation (SdkObject subclasses)
channels.d.ts — generated server channel interfaces
server/dispatchers/ — protocol bridge (Dispatcher subclasses)
protocol/ — validators (generated + primitives)
utils/isomorphic/ — shared code used by both client and server
Expand Down
1 change: 0 additions & 1 deletion packages/dashboard/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default defineConfig({
resolve: {
alias: {
'@isomorphic': path.resolve(__dirname, '../isomorphic'),
'@protocol': path.resolve(__dirname, '../protocol/src'),
'@web': path.resolve(__dirname, '../web/src'),
'@trace-viewer': path.resolve(__dirname, '../trace-viewer/src'),
},
Expand Down
31 changes: 25 additions & 6 deletions packages/injected/src/injectedScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import type { AriaTemplateNode } from '@isomorphic/ariaSnapshot';
import type { CSSComplexSelectorList } from '@isomorphic/cssParser';
import type { Language } from '@isomorphic/locatorGenerators';
import type { AttributeSelectorPart, NestedSelectorBody, ParsedSelector, ParsedSelectorPart } from '@isomorphic/selectorParser';
import type * as channels from '@protocol/channels';
import type { AriaSnapshot, AriaTreeOptions } from './ariaSnapshot';
import type { LayoutSelectorName } from './layoutSelectorUtils';
import type { SelectorEngine, SelectorRoot } from './selectorEngine';
Expand All @@ -46,8 +45,28 @@ import type { ElementText, TextMatcher } from './selectorUtils';
import type { Builtins } from './utilityScript';


export type FrameExpectParams = Omit<channels.FrameExpectParams, 'expectedValue' | 'timeout'> & {
expectedValue?: any;
type ExpectedTextValue = {
string?: string,
regexSource?: string,
regexFlags?: string,
matchSubstring?: boolean,
ignoreCase?: boolean,
normalizeWhiteSpace?: boolean,
};

type Point = { x: number, y: number };
type Rect = Point & { width: number, height: number };

export type FrameExpectParams = {
selector?: string,
expression: string,
expressionArg?: any,
pseudo?: 'before' | 'after',
expectedText?: ExpectedTextValue[],
expectedNumber?: number,
expectedValue?: any,
useInnerText?: boolean,
isNot: boolean,
};

export type ElementState = 'visible' | 'hidden' | 'enabled' | 'disabled' | 'editable' | 'checked' | 'unchecked' | 'indeterminate' | 'stable';
Expand Down Expand Up @@ -1337,7 +1356,7 @@ export class InjectedScript {
highlight.removeElementHighlight(selector);
}

setScreencastAnnotation(annotation: { point?: channels.Point, box?: channels.Rect, actionTitle?: string, duration?: number, position?: string, fontSize?: number, cursor?: 'none' | 'pointer' } | null) {
setScreencastAnnotation(annotation: { point?: Point, box?: Rect, actionTitle?: string, duration?: number, position?: string, fontSize?: number, cursor?: 'none' | 'pointer' } | null) {
const highlight = this._ensureHighlight();
if (!annotation) {
highlight.updateHighlight([]);
Expand Down Expand Up @@ -1722,7 +1741,7 @@ export class InjectedScript {
}

private _matchSequentially<T>(
expectedText: channels.ExpectedTextValue[],
expectedText: ExpectedTextValue[],
received: T[],
matchFn: (matcher: ExpectedTextMatcher, received: T) => boolean
): boolean {
Expand Down Expand Up @@ -1811,7 +1830,7 @@ class ExpectedTextMatcher {
private _normalizeWhiteSpace: boolean | undefined;
private _ignoreCase: boolean | undefined;

constructor(expected: channels.ExpectedTextValue) {
constructor(expected: ExpectedTextValue) {
this._normalizeWhiteSpace = expected.normalizeWhiteSpace;
this._ignoreCase = expected.ignoreCase;
this._string = expected.matchSubstring ? undefined : this.normalize(expected.string);
Expand Down
45 changes: 39 additions & 6 deletions packages/injected/src/storageScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,42 @@

import { parseEvaluationResultValue, serializeAsCallArgument } from '@isomorphic/utilityScriptSerializers';

import type * as channels from '@protocol/channels';

export type SerializedStorage = Omit<channels.OriginStorage, 'origin'>;
type NameValue = { name: string, value: string };

type IndexedDBDatabase = {
name: string,
version: number,
stores: {
name: string,
autoIncrement: boolean,
keyPath?: string,
keyPathArray?: string[],
records: {
key?: any,
keyEncoded?: any,
value?: any,
valueEncoded?: any,
}[],
indexes: {
name: string,
keyPath?: string,
keyPathArray?: string[],
multiEntry: boolean,
unique: boolean,
}[],
}[],
};

type SetOriginStorage = {
origin: string,
localStorage: NameValue[],
indexedDB?: IndexedDBDatabase[],
};

export type SerializedStorage = {
localStorage: NameValue[],
indexedDB?: IndexedDBDatabase[],
};

export class StorageScript {
private _isFirefox: boolean;
Expand Down Expand Up @@ -85,7 +118,7 @@ export class StorageScript {

const keys = await this._idbRequestToPromise(objectStore.getAllKeys());
const records = await Promise.all(keys.map(async key => {
const record: channels.IndexedDBDatabase['stores'][0]['records'][0] = {};
const record: IndexedDBDatabase['stores'][0]['records'][0] = {};

if (objectStore.keyPath === null) {
const { encoded, trivial } = this._trySerialize(key);
Expand Down Expand Up @@ -146,7 +179,7 @@ export class StorageScript {
}
}

private async _restoreDB(dbInfo: channels.IndexedDBDatabase) {
private async _restoreDB(dbInfo: IndexedDBDatabase) {
const openRequest = this._global.indexedDB.open(dbInfo.name, dbInfo.version);
openRequest.addEventListener('upgradeneeded', () => {
const db = openRequest.result;
Expand Down Expand Up @@ -176,7 +209,7 @@ export class StorageScript {
}));
}

async restore(originState: channels.SetOriginStorage | undefined) {
async restore(originState: SetOriginStorage | undefined) {
// Clean Service Workers.
const registrations = this._global.navigator.serviceWorker ? await this._global.navigator.serviceWorker.getRegistrations() : [];
await Promise.all(registrations.map(async r => {
Expand Down
29 changes: 0 additions & 29 deletions packages/isomorphic/expectUtils.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/isomorphic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

export * from './ariaSnapshot';
export * from './expectUtils';
export * from './assert';
export * from './base64';
export * from './colors';
Expand Down
19 changes: 14 additions & 5 deletions packages/isomorphic/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type * as fs from 'fs';
import type * as path from 'path';
import type { Readable, Writable } from 'stream';
import type { Colors } from '@isomorphic/colors';
import type * as channels from '@protocol/channels';

export type Zone = {
push(data: unknown): Zone;
Expand All @@ -29,6 +28,16 @@ export type Zone = {
data<T>(): T | undefined;
};

export type StreamChannel = {
read(params: { size?: number }): Promise<{ binary: Buffer }>;
close(params?: {}): Promise<any>;
};

export type WritableStreamChannel = {
write(params: { binary: Buffer }): Promise<any>;
close(params?: {}): Promise<any>;
};

const noopZone: Zone = {
push: () => noopZone,
pop: () => noopZone,
Expand Down Expand Up @@ -57,8 +66,8 @@ export type Platform = {
pathSeparator: string;
showInternalStackFrames: () => boolean,
streamFile: (path: string, writable: Writable) => Promise<void>,
streamReadable: (channel: channels.StreamChannel) => Readable,
streamWritable: (channel: channels.WritableStreamChannel) => Writable,
streamReadable: (channel: StreamChannel) => Readable,
streamWritable: (channel: WritableStreamChannel) => Writable,
zones: { empty: Zone, current: () => Zone; };
};

Expand Down Expand Up @@ -111,11 +120,11 @@ export const emptyPlatform: Platform = {
throw new Error('Streams are not available');
},

streamReadable: (channel: channels.StreamChannel) => {
streamReadable: (channel: StreamChannel) => {
throw new Error('Streams are not available');
},

streamWritable: (channel: channels.WritableStreamChannel) => {
streamWritable: (channel: WritableStreamChannel) => {
throw new Error('Streams are not available');
},

Expand Down
2 changes: 1 addition & 1 deletion packages/isomorphic/trace/traceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

import { getActionGroup, renderTitleForCall } from '../protocolFormatter';

import type { StackFrame } from '../stackTrace';
import type { Language } from '../locatorGenerators';
import type { ResourceSnapshot } from '@trace/snapshot';
import type * as trace from '@trace/trace';
import type { ActionTraceEvent } from '@trace/trace';
import type { ActionEntry, ContextEntry, PageEntry } from './entries';
import type { StackFrame } from '@protocol/channels';
import type { ActionGroup } from '../protocolFormatter';

const contextSymbol = Symbol('context');
Expand Down
7 changes: 6 additions & 1 deletion packages/isomorphic/trace/traceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import type { ClientSideCallMetadata, StackFrame } from '@protocol/channels';
import type { StackFrame } from '../stackTrace';

type ClientSideCallMetadata = {
id: number,
stack?: StackFrame[],
};

export type SerializedStackFrame = [number, number, number, string];
export type SerializedStack = [number, SerializedStackFrame[]];
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type * as types from './types';
import type * as api from '../../types/types';
import type { AndroidServerLauncherImpl } from '../androidServerImpl';
import type { Platform } from '@isomorphic/platform';
import type * as channels from '@protocol/channels';
import type * as channels from './channels';
import type { Playwright } from './playwright';

type Direction = 'down' | 'up' | 'left' | 'right';
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ChannelOwner } from './channelOwner';
import { Stream } from './stream';
import { mkdirIfNeeded } from './fileUtils';

import type * as channels from '@protocol/channels';
import type * as channels from './channels';
import type { Readable } from 'stream';

export class Artifact extends ChannelOwner<channels.ArtifactChannel> {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { BrowserType } from './browserType';
import type { Page } from './page';
import type { BrowserContextOptions, LaunchOptions, Logger } from './types';
import type * as api from '../../types/types';
import type * as channels from '@protocol/channels';
import type * as channels from './channels';

export class Browser extends ChannelOwner<channels.BrowserChannel> implements api.Browser {
readonly _contexts = new Set<BrowserContext>();
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type * as structs from '../../types/structs';
import type * as api from '../../types/types';
import type { URLMatch } from '@isomorphic/urlMatch';
import type { Platform } from '@isomorphic/platform';
import type * as channels from '@protocol/channels';
import type * as channels from './channels';
import type * as actions from '@recorder/actions';

interface RecorderEventSink {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Worker } from './worker';
import type { Playwright } from './playwright';
import type { ConnectOptions, LaunchOptions, LaunchPersistentContextOptions, LaunchServerOptions } from './types';
import type * as api from '../../types/types';
import type * as channels from '@protocol/channels';
import type * as channels from './channels';
import type { ChildProcess } from 'child_process';

export interface BrowserServerLauncher {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/cdpSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ChannelOwner } from './channelOwner';

import type * as api from '../../types/types';
import type { Protocol } from '../server/chromium/protocol';
import type * as channels from '@protocol/channels';
import type * as channels from './channels';

export class CDPSession extends ChannelOwner<channels.CDPSessionChannel> implements api.CDPSession {
static from(cdpSession: channels.CDPSessionChannel): CDPSession {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/channelOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { Connection } from './connection';
import type { Logger } from './types';
import type { ValidatorContext } from '../protocol/validator';
import type { Platform } from '@isomorphic/platform';
import type * as channels from '@protocol/channels';
import type * as channels from './channels';

type Listener = (...args: any[]) => void;

Expand Down
Loading
Loading