mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(driver): report backend state (#16477)
This commit is contained in:
parent
51076d55ad
commit
fce45210c1
@ -90,6 +90,38 @@ class ProtocolHandler {
|
||||
|
||||
constructor(playwright: Playwright) {
|
||||
this._playwright = playwright;
|
||||
playwright.instrumentation.addListener({
|
||||
onPageOpen: () => this._sendSnapshot(),
|
||||
onPageNavigated: () => this._sendSnapshot(),
|
||||
onPageClose: () => this._sendSnapshot(),
|
||||
}, null);
|
||||
}
|
||||
|
||||
private _sendSnapshot() {
|
||||
const browsers = [];
|
||||
for (const browser of this._playwright.allBrowsers()) {
|
||||
const b = {
|
||||
name: browser.options.name,
|
||||
guid: browser.guid,
|
||||
contexts: [] as any[]
|
||||
};
|
||||
browsers.push(b);
|
||||
for (const context of browser.contexts()) {
|
||||
const c = {
|
||||
guid: context.guid,
|
||||
pages: [] as any[]
|
||||
};
|
||||
b.contexts.push(c);
|
||||
for (const page of context.pages()) {
|
||||
const p = {
|
||||
guid: page.guid,
|
||||
url: page.mainFrame().url()
|
||||
};
|
||||
c.pages.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
process.send!({ method: 'browsersChanged', params: { browsers } });
|
||||
}
|
||||
|
||||
async resetForReuse() {
|
||||
|
||||
@ -239,7 +239,7 @@ export class FrameManager {
|
||||
|
||||
frame._onClearLifecycle();
|
||||
const navigationEvent: NavigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
|
||||
frame.emit(Frame.Events.InternalNavigation, navigationEvent);
|
||||
this._fireInternalFrameNavigation(frame, navigationEvent);
|
||||
if (!initial) {
|
||||
debugLogger.log('api', ` navigated to "${url}"`);
|
||||
this._page.frameNavigatedToNewDocument(frame);
|
||||
@ -254,7 +254,7 @@ export class FrameManager {
|
||||
return;
|
||||
frame._url = url;
|
||||
const navigationEvent: NavigationEvent = { url, name: frame._name, isPublic: true };
|
||||
frame.emit(Frame.Events.InternalNavigation, navigationEvent);
|
||||
this._fireInternalFrameNavigation(frame, navigationEvent);
|
||||
debugLogger.log('api', ` navigated to "${url}"`);
|
||||
}
|
||||
|
||||
@ -272,7 +272,7 @@ export class FrameManager {
|
||||
isPublic: !(documentId && frame._redirectedNavigations.has(documentId)),
|
||||
};
|
||||
frame.setPendingDocument(undefined);
|
||||
frame.emit(Frame.Events.InternalNavigation, navigationEvent);
|
||||
this._fireInternalFrameNavigation(frame, navigationEvent);
|
||||
}
|
||||
|
||||
frameDetached(frameId: string) {
|
||||
@ -462,6 +462,12 @@ export class FrameManager {
|
||||
if (ws)
|
||||
ws.error(errorMessage);
|
||||
}
|
||||
|
||||
private _fireInternalFrameNavigation(frame: Frame, event: NavigationEvent) {
|
||||
frame.emit(Frame.Events.InternalNavigation, event);
|
||||
if (event.isPublic && !frame.parentFrame())
|
||||
frame.instrumentation.onPageNavigated(frame._page, event.url);
|
||||
}
|
||||
}
|
||||
|
||||
export class Frame extends SdkObject {
|
||||
|
||||
@ -63,6 +63,7 @@ export interface Instrumentation {
|
||||
onAfterCall(sdkObject: SdkObject, metadata: CallMetadata): Promise<void>;
|
||||
onEvent(sdkObject: SdkObject, metadata: CallMetadata): void;
|
||||
onPageOpen(page: Page): void;
|
||||
onPageNavigated(page: Page, url: string): void;
|
||||
onPageClose(page: Page): void;
|
||||
onBrowserOpen(browser: Browser): void;
|
||||
onBrowserClose(browser: Browser): void;
|
||||
@ -75,6 +76,7 @@ export interface InstrumentationListener {
|
||||
onAfterCall?(sdkObject: SdkObject, metadata: CallMetadata): Promise<void>;
|
||||
onEvent?(sdkObject: SdkObject, metadata: CallMetadata): void;
|
||||
onPageOpen?(page: Page): void;
|
||||
onPageNavigated?(page: Page, url: string): void;
|
||||
onPageClose?(page: Page): void;
|
||||
onBrowserOpen?(browser: Browser): void;
|
||||
onBrowserClose?(browser: Browser): void;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user