Skip to content
Merged
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
8 changes: 8 additions & 0 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ scheme.LocalUtilsTraceDiscardedParams = tObject({
stacksId: tString,
});
scheme.LocalUtilsTraceDiscardedResult = tOptional(tObject({}));
scheme.LocalUtilsGlobToRegexParams = tObject({
glob: tString,
baseURL: tOptional(tString),
webSocketUrl: tOptional(tBoolean),
});
scheme.LocalUtilsGlobToRegexResult = tObject({
regex: tString,
});
scheme.RootInitializer = tOptional(tObject({}));
scheme.RootInitializeParams = tObject({
sdkLanguage: tType('SDKLanguage'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Progress } from '../progress';
import { SocksInterceptor } from '../socksInterceptor';
import { WebSocketTransport } from '../transport';
import { fetchData } from '../utils/network';
import { resolveGlobToRegexPattern } from '../../utils/isomorphic/urlMatch';

import type { HarBackend } from '../harBackend';
import type { Playwright } from '../playwright';
Expand Down Expand Up @@ -116,6 +117,11 @@ export class LocalUtilsDispatcher extends Dispatcher<SdkObject, channels.LocalUt
pipe.on('close', () => transport.close());
return { pipe, headers: transport.headers };
}

async globToRegex(params: channels.LocalUtilsGlobToRegexParams, progress: Progress): Promise<channels.LocalUtilsGlobToRegexResult> {
const regex = resolveGlobToRegexPattern(params.baseURL, params.glob, params.webSocketUrl);
return { regex };
}
}

async function urlToWSEndpoint(progress: Progress, endpointURL: string): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const methodMetainfo = new Map<string, { internal?: boolean, title?: stri
['LocalUtils.tracingStarted', { internal: true, }],
['LocalUtils.addStackToTracingNoReply', { internal: true, }],
['LocalUtils.traceDiscarded', { internal: true, }],
['LocalUtils.globToRegex', { internal: true, }],
['Root.initialize', { internal: true, }],
['Playwright.newRequest', { title: 'Create request context', }],
['DebugController.initialize', { internal: true, }],
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/utils/isomorphic/urlMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function urlMatches(baseURL: string | undefined, urlString: string, match
return match(url);
}

function resolveGlobToRegexPattern(baseURL: string | undefined, glob: string, webSocketUrl?: boolean): string {
export function resolveGlobToRegexPattern(baseURL: string | undefined, glob: string, webSocketUrl?: boolean): string {
if (webSocketUrl)
baseURL = toWebSocketBaseUrl(baseURL);
glob = resolveGlobBase(baseURL, glob);
Expand Down
13 changes: 13 additions & 0 deletions packages/protocol/src/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ export interface LocalUtilsChannel extends LocalUtilsEventTarget, Channel {
tracingStarted(params: LocalUtilsTracingStartedParams, progress?: Progress): Promise<LocalUtilsTracingStartedResult>;
addStackToTracingNoReply(params: LocalUtilsAddStackToTracingNoReplyParams, progress?: Progress): Promise<LocalUtilsAddStackToTracingNoReplyResult>;
traceDiscarded(params: LocalUtilsTraceDiscardedParams, progress?: Progress): Promise<LocalUtilsTraceDiscardedResult>;
globToRegex(params: LocalUtilsGlobToRegexParams, progress?: Progress): Promise<LocalUtilsGlobToRegexResult>;
}
export type LocalUtilsZipParams = {
zipFile: string,
Expand Down Expand Up @@ -583,6 +584,18 @@ export type LocalUtilsTraceDiscardedOptions = {

};
export type LocalUtilsTraceDiscardedResult = void;
export type LocalUtilsGlobToRegexParams = {
glob: string,
baseURL?: string,
webSocketUrl?: boolean,
};
export type LocalUtilsGlobToRegexOptions = {
baseURL?: string,
webSocketUrl?: boolean,
};
export type LocalUtilsGlobToRegexResult = {
regex: string,
};

export interface LocalUtilsEvents {
}
Expand Down
8 changes: 8 additions & 0 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,14 @@ LocalUtils:
parameters:
stacksId: string

globToRegex:
internal: true
parameters:
glob: string
baseURL: string?
webSocketUrl: boolean?
returns:
regex: string

Root:
type: interface
Expand Down
Loading