chore: expose hidehighlight from server (#16387)
This commit is contained in:
parent
92aacb9345
commit
737975bc7d
|
|
@ -143,6 +143,10 @@ class ProtocolHandler {
|
||||||
recorder.setHighlightedSelector(params.selector);
|
recorder.setHighlightedSelector(params.selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async hideHighlight() {
|
||||||
|
await this._playwright.hideHighlight();
|
||||||
|
}
|
||||||
|
|
||||||
async kill() {
|
async kill() {
|
||||||
selfDestruct();
|
selfDestruct();
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +180,7 @@ async function allRecorders(playwright: Playwright): Promise<Recorder[]> {
|
||||||
const contexts = new Set<BrowserContext>();
|
const contexts = new Set<BrowserContext>();
|
||||||
for (const page of playwright.allPages())
|
for (const page of playwright.allPages())
|
||||||
contexts.add(page.context());
|
contexts.add(page.context());
|
||||||
const result = await Promise.all([...contexts].map(c => Recorder.show(c, {}, () => Promise.resolve(new InspectingRecorderApp()))));
|
const result = await Promise.all([...contexts].map(c => Recorder.show(c, { omitCallTracking: true }, () => Promise.resolve(new InspectingRecorderApp()))));
|
||||||
return result.filter(Boolean) as Recorder[];
|
return result.filter(Boolean) as Recorder[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1424,6 +1424,7 @@ export type BrowserContextRecorderSupplementEnableParams = {
|
||||||
saveStorage?: string,
|
saveStorage?: string,
|
||||||
outputFile?: string,
|
outputFile?: string,
|
||||||
handleSIGINT?: boolean,
|
handleSIGINT?: boolean,
|
||||||
|
omitCallTracking?: boolean,
|
||||||
};
|
};
|
||||||
export type BrowserContextRecorderSupplementEnableOptions = {
|
export type BrowserContextRecorderSupplementEnableOptions = {
|
||||||
language?: string,
|
language?: string,
|
||||||
|
|
@ -1435,6 +1436,7 @@ export type BrowserContextRecorderSupplementEnableOptions = {
|
||||||
saveStorage?: string,
|
saveStorage?: string,
|
||||||
outputFile?: string,
|
outputFile?: string,
|
||||||
handleSIGINT?: boolean,
|
handleSIGINT?: boolean,
|
||||||
|
omitCallTracking?: boolean,
|
||||||
};
|
};
|
||||||
export type BrowserContextRecorderSupplementEnableResult = void;
|
export type BrowserContextRecorderSupplementEnableResult = void;
|
||||||
export type BrowserContextNewCDPSessionParams = {
|
export type BrowserContextNewCDPSessionParams = {
|
||||||
|
|
|
||||||
|
|
@ -949,6 +949,7 @@ BrowserContext:
|
||||||
saveStorage: string?
|
saveStorage: string?
|
||||||
outputFile: string?
|
outputFile: string?
|
||||||
handleSIGINT: boolean?
|
handleSIGINT: boolean?
|
||||||
|
omitCallTracking: boolean?
|
||||||
|
|
||||||
newCDPSession:
|
newCDPSession:
|
||||||
parameters:
|
parameters:
|
||||||
|
|
|
||||||
|
|
@ -773,6 +773,7 @@ scheme.BrowserContextRecorderSupplementEnableParams = tObject({
|
||||||
saveStorage: tOptional(tString),
|
saveStorage: tOptional(tString),
|
||||||
outputFile: tOptional(tString),
|
outputFile: tOptional(tString),
|
||||||
handleSIGINT: tOptional(tBoolean),
|
handleSIGINT: tOptional(tBoolean),
|
||||||
|
omitCallTracking: tOptional(tBoolean),
|
||||||
});
|
});
|
||||||
scheme.BrowserContextRecorderSupplementEnableResult = tOptional(tObject({}));
|
scheme.BrowserContextRecorderSupplementEnableResult = tOptional(tObject({}));
|
||||||
scheme.BrowserContextNewCDPSessionParams = tObject({
|
scheme.BrowserContextNewCDPSessionParams = tObject({
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { stringifySelector } from '../isomorphic/selectorParser';
|
||||||
|
import type { ParsedSelector } from '../isomorphic/selectorParser';
|
||||||
|
import type { InjectedScript } from './injectedScript';
|
||||||
|
|
||||||
type HighlightEntry = {
|
type HighlightEntry = {
|
||||||
targetElement: Element,
|
targetElement: Element,
|
||||||
highlightElement: HTMLElement,
|
highlightElement: HTMLElement,
|
||||||
|
|
@ -29,9 +33,12 @@ export class Highlight {
|
||||||
private _highlightEntries: HighlightEntry[] = [];
|
private _highlightEntries: HighlightEntry[] = [];
|
||||||
private _actionPointElement: HTMLElement;
|
private _actionPointElement: HTMLElement;
|
||||||
private _isUnderTest: boolean;
|
private _isUnderTest: boolean;
|
||||||
|
private _injectedScript: InjectedScript;
|
||||||
|
private _rafRequest: number | undefined;
|
||||||
|
|
||||||
constructor(isUnderTest: boolean) {
|
constructor(injectedScript: InjectedScript) {
|
||||||
this._isUnderTest = isUnderTest;
|
this._injectedScript = injectedScript;
|
||||||
|
this._isUnderTest = injectedScript.isUnderTest;
|
||||||
this._glassPaneElement = document.createElement('x-pw-glass');
|
this._glassPaneElement = document.createElement('x-pw-glass');
|
||||||
this._glassPaneElement.style.position = 'fixed';
|
this._glassPaneElement.style.position = 'fixed';
|
||||||
this._glassPaneElement.style.top = '0';
|
this._glassPaneElement.style.top = '0';
|
||||||
|
|
@ -95,7 +102,16 @@ export class Highlight {
|
||||||
document.documentElement.appendChild(this._glassPaneElement);
|
document.documentElement.appendChild(this._glassPaneElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runHighlightOnRaf(selector: ParsedSelector) {
|
||||||
|
if (this._rafRequest)
|
||||||
|
cancelAnimationFrame(this._rafRequest);
|
||||||
|
this.updateHighlight(this._injectedScript.querySelectorAll(selector, document.documentElement), stringifySelector(selector), false);
|
||||||
|
this._rafRequest = requestAnimationFrame(() => this.runHighlightOnRaf(selector));
|
||||||
|
}
|
||||||
|
|
||||||
uninstall() {
|
uninstall() {
|
||||||
|
if (this._rafRequest)
|
||||||
|
cancelAnimationFrame(this._rafRequest);
|
||||||
this._glassPaneElement.remove();
|
this._glassPaneElement.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -956,7 +956,7 @@ export class InjectedScript {
|
||||||
maskSelectors(selectors: ParsedSelector[]) {
|
maskSelectors(selectors: ParsedSelector[]) {
|
||||||
if (this._highlight)
|
if (this._highlight)
|
||||||
this.hideHighlight();
|
this.hideHighlight();
|
||||||
this._highlight = new Highlight(this.isUnderTest);
|
this._highlight = new Highlight(this);
|
||||||
this._highlight.install();
|
this._highlight.install();
|
||||||
const elements = [];
|
const elements = [];
|
||||||
for (const selector of selectors)
|
for (const selector of selectors)
|
||||||
|
|
@ -966,17 +966,10 @@ export class InjectedScript {
|
||||||
|
|
||||||
highlight(selector: ParsedSelector) {
|
highlight(selector: ParsedSelector) {
|
||||||
if (!this._highlight) {
|
if (!this._highlight) {
|
||||||
this._highlight = new Highlight(this.isUnderTest);
|
this._highlight = new Highlight(this);
|
||||||
this._highlight.install();
|
this._highlight.install();
|
||||||
}
|
}
|
||||||
this._runHighlightOnRaf(selector);
|
this._highlight.runHighlightOnRaf(selector);
|
||||||
}
|
|
||||||
|
|
||||||
_runHighlightOnRaf(selector: ParsedSelector) {
|
|
||||||
if (!this._highlight)
|
|
||||||
return;
|
|
||||||
this._highlight.updateHighlight(this.querySelectorAll(selector, document.documentElement), stringifySelector(selector), false);
|
|
||||||
requestAnimationFrame(() => this._runHighlightOnRaf(selector));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hideHighlight() {
|
hideHighlight() {
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class Recorder {
|
||||||
|
|
||||||
constructor(injectedScript: InjectedScript) {
|
constructor(injectedScript: InjectedScript) {
|
||||||
this._injectedScript = injectedScript;
|
this._injectedScript = injectedScript;
|
||||||
this._highlight = new Highlight(injectedScript.isUnderTest);
|
this._highlight = new Highlight(injectedScript);
|
||||||
|
|
||||||
this._refreshListenersIfNeeded();
|
this._refreshListenersIfNeeded();
|
||||||
injectedScript.onGlobalListenersRemoved.add(() => this._refreshListenersIfNeeded());
|
injectedScript.onGlobalListenersRemoved.add(() => this._refreshListenersIfNeeded());
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,11 @@ export class Recorder implements InstrumentationListener {
|
||||||
private _currentCallsMetadata = new Map<CallMetadata, SdkObject>();
|
private _currentCallsMetadata = new Map<CallMetadata, SdkObject>();
|
||||||
private _recorderSources: Source[] = [];
|
private _recorderSources: Source[] = [];
|
||||||
private _userSources = new Map<string, Source>();
|
private _userSources = new Map<string, Source>();
|
||||||
private _allMetadatas = new Map<string, CallMetadata>();
|
|
||||||
private _debugger: Debugger;
|
private _debugger: Debugger;
|
||||||
private _contextRecorder: ContextRecorder;
|
private _contextRecorder: ContextRecorder;
|
||||||
private _handleSIGINT: boolean | undefined;
|
private _handleSIGINT: boolean | undefined;
|
||||||
private _recorderAppFactory: (recorder: Recorder) => Promise<IRecorderApp>;
|
private _recorderAppFactory: (recorder: Recorder) => Promise<IRecorderApp>;
|
||||||
|
private _omitCallTracking = false;
|
||||||
|
|
||||||
static showInspector(context: BrowserContext) {
|
static showInspector(context: BrowserContext) {
|
||||||
Recorder.show(context, {}).catch(() => {});
|
Recorder.show(context, {}).catch(() => {});
|
||||||
|
|
@ -79,6 +79,7 @@ export class Recorder implements InstrumentationListener {
|
||||||
this._recorderAppFactory = recorderAppFactory;
|
this._recorderAppFactory = recorderAppFactory;
|
||||||
this._contextRecorder = new ContextRecorder(context, params);
|
this._contextRecorder = new ContextRecorder(context, params);
|
||||||
this._context = context;
|
this._context = context;
|
||||||
|
this._omitCallTracking = !!params.omitCallTracking;
|
||||||
this._debugger = Debugger.lookup(context)!;
|
this._debugger = Debugger.lookup(context)!;
|
||||||
this._handleSIGINT = params.handleSIGINT;
|
this._handleSIGINT = params.handleSIGINT;
|
||||||
context.instrumentation.addListener(this, context);
|
context.instrumentation.addListener(this, context);
|
||||||
|
|
@ -215,10 +216,9 @@ export class Recorder implements InstrumentationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onBeforeCall(sdkObject: SdkObject, metadata: CallMetadata) {
|
async onBeforeCall(sdkObject: SdkObject, metadata: CallMetadata) {
|
||||||
if (this._mode === 'recording')
|
if (this._omitCallTracking || this._mode === 'recording')
|
||||||
return;
|
return;
|
||||||
this._currentCallsMetadata.set(metadata, sdkObject);
|
this._currentCallsMetadata.set(metadata, sdkObject);
|
||||||
this._allMetadatas.set(metadata.id, metadata);
|
|
||||||
this._updateUserSources();
|
this._updateUserSources();
|
||||||
this.updateCallLog([metadata]);
|
this.updateCallLog([metadata]);
|
||||||
if (metadata.params && metadata.params.selector) {
|
if (metadata.params && metadata.params.selector) {
|
||||||
|
|
@ -228,7 +228,7 @@ export class Recorder implements InstrumentationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onAfterCall(sdkObject: SdkObject, metadata: CallMetadata) {
|
async onAfterCall(sdkObject: SdkObject, metadata: CallMetadata) {
|
||||||
if (this._mode === 'recording')
|
if (this._omitCallTracking || this._mode === 'recording')
|
||||||
return;
|
return;
|
||||||
if (!metadata.error)
|
if (!metadata.error)
|
||||||
this._currentCallsMetadata.delete(metadata);
|
this._currentCallsMetadata.delete(metadata);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue