2020-01-09 14:49:22 -08:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-12-09 15:06:57 -08:00
|
|
|
import { Android } from './android/android';
|
|
|
|
import { AdbBackend } from './android/backendAdb';
|
2022-07-31 14:31:17 -07:00
|
|
|
import type { Browser, PlaywrightOptions } from './browser';
|
2020-08-22 15:46:42 -07:00
|
|
|
import { Chromium } from './chromium/chromium';
|
2020-12-09 15:06:57 -08:00
|
|
|
import { Electron } from './electron/electron';
|
2020-08-23 17:05:58 -07:00
|
|
|
import { Firefox } from './firefox/firefox';
|
2021-06-15 14:56:29 -07:00
|
|
|
import { Selectors } from './selectors';
|
2020-12-09 15:06:57 -08:00
|
|
|
import { WebKit } from './webkit/webkit';
|
2022-04-06 13:57:14 -08:00
|
|
|
import type { CallMetadata } from './instrumentation';
|
|
|
|
import { createInstrumentation, SdkObject } from './instrumentation';
|
2022-04-07 13:36:13 -08:00
|
|
|
import { debugLogger } from '../common/debugLogger';
|
2022-04-06 13:57:14 -08:00
|
|
|
import type { Page } from './page';
|
2020-01-09 14:49:22 -08:00
|
|
|
|
2021-02-09 09:00:00 -08:00
|
|
|
export class Playwright extends SdkObject {
|
|
|
|
readonly selectors: Selectors;
|
2020-07-24 16:36:00 -07:00
|
|
|
readonly chromium: Chromium;
|
2020-12-09 15:06:57 -08:00
|
|
|
readonly android: Android;
|
|
|
|
readonly electron: Electron;
|
2020-07-24 16:36:00 -07:00
|
|
|
readonly firefox: Firefox;
|
|
|
|
readonly webkit: WebKit;
|
2021-01-31 16:37:13 -08:00
|
|
|
readonly options: PlaywrightOptions;
|
2022-01-12 07:37:48 -08:00
|
|
|
private _allPages = new Set<Page>();
|
2022-07-31 14:31:17 -07:00
|
|
|
private _allBrowsers = new Set<Browser>();
|
2020-01-24 14:49:47 -08:00
|
|
|
|
2022-03-17 17:27:33 -08:00
|
|
|
constructor(sdkLanguage: string, isInternalPlaywright: boolean) {
|
|
|
|
super({ attribution: { isInternalPlaywright }, instrumentation: createInstrumentation() } as any, undefined, 'Playwright');
|
2021-04-26 16:20:38 -07:00
|
|
|
this.instrumentation.addListener({
|
2022-07-31 14:31:17 -07:00
|
|
|
onBrowserOpen: browser => this._allBrowsers.add(browser),
|
|
|
|
onBrowserClose: browser => this._allBrowsers.delete(browser),
|
2022-01-12 07:37:48 -08:00
|
|
|
onPageOpen: page => this._allPages.add(page),
|
|
|
|
onPageClose: page => this._allPages.delete(page),
|
|
|
|
onCallLog: (sdkObject: SdkObject, metadata: CallMetadata, logName: string, message: string) => {
|
2021-04-26 16:20:38 -07:00
|
|
|
debugLogger.log(logName as any, message);
|
|
|
|
}
|
2022-01-12 07:37:48 -08:00
|
|
|
}, null);
|
2021-01-31 16:37:13 -08:00
|
|
|
this.options = {
|
2021-02-09 09:00:00 -08:00
|
|
|
rootSdkObject: this,
|
2021-06-15 14:56:29 -07:00
|
|
|
selectors: new Selectors(),
|
2021-08-20 21:32:21 +02:00
|
|
|
sdkLanguage: sdkLanguage,
|
2021-01-31 16:37:13 -08:00
|
|
|
};
|
2021-02-08 16:02:49 -08:00
|
|
|
this.chromium = new Chromium(this.options);
|
|
|
|
this.firefox = new Firefox(this.options);
|
|
|
|
this.webkit = new WebKit(this.options);
|
|
|
|
this.electron = new Electron(this.options);
|
|
|
|
this.android = new Android(new AdbBackend(), this.options);
|
2021-06-15 14:56:29 -07:00
|
|
|
this.selectors = this.options.selectors;
|
2020-01-24 14:49:47 -08:00
|
|
|
}
|
2022-01-12 07:37:48 -08:00
|
|
|
|
|
|
|
async hideHighlight() {
|
|
|
|
await Promise.all([...this._allPages].map(p => p.hideHighlight().catch(() => {})));
|
|
|
|
}
|
2022-07-31 14:31:17 -07:00
|
|
|
|
|
|
|
allBrowsers(): Browser[] {
|
|
|
|
return [...this._allBrowsers];
|
|
|
|
}
|
2020-01-09 14:49:22 -08:00
|
|
|
}
|
2021-01-29 16:00:56 -08:00
|
|
|
|
2022-03-17 17:27:33 -08:00
|
|
|
export function createPlaywright(sdkLanguage: string, isInternalPlaywright: boolean = false) {
|
|
|
|
return new Playwright(sdkLanguage, isInternalPlaywright);
|
2021-01-29 16:00:56 -08:00
|
|
|
}
|