///
/**
* Copyright 2018 Google Inc. All rights reserved.
* Modifications copyright (c) Data Liberation Foundation Inc.
*
* 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.
*/
import Protocol from 'devtools-protocol';
import { IPage, IPageEvents } from '@unblocked-web/specifications/agent/browser/IPage';
import { TypedEventEmitter } from '@ulixee/commons/lib/eventUtils';
import IRegisteredEventListener from '@ulixee/commons/interfaces/IRegisteredEventListener';
import { IBoundLog } from '@ulixee/commons/interfaces/ILog';
import IScreenshotOptions from '@unblocked-web/specifications/agent/browser/IScreenshotOptions';
import { IElementInteractVerification, IInteractionGroup } from '@unblocked-web/specifications/agent/interact/IInteractions';
import IResourceMeta from '@unblocked-web/specifications/agent/net/IResourceMeta';
import { ILoadStatus, LoadStatus } from '@unblocked-web/specifications/agent/browser/Location';
import { IJsPath } from '@unblocked-web/js-path';
import INavigation from '@unblocked-web/specifications/agent/browser/INavigation';
import IExecJsPathResult from '@unblocked-web/specifications/agent/browser/IExecJsPathResult';
import IDialog from '@unblocked-web/specifications/agent/browser/IDialog';
import { IFrame } from '@unblocked-web/specifications/agent/browser/IFrame';
import DevtoolsSession from './DevtoolsSession';
import NetworkManager from './NetworkManager';
import { Keyboard } from './Keyboard';
import Mouse from './Mouse';
import FramesManager from './FramesManager';
import BrowserContext from './BrowserContext';
import { Worker } from './Worker';
import Frame from './Frame';
import IWaitForOptions from '../interfaces/IWaitForOptions';
import DomStorageTracker, { IDomStorageEvents } from './DomStorageTracker';
import TargetInfo = Protocol.Target.TargetInfo;
export interface IPageCreateOptions {
groupName?: string;
runPageScripts?: boolean;
enableDomStorageTracker?: boolean;
triggerPopupOnPageId?: string;
installJsPathIntoDefaultContext?: boolean;
}
interface IPageLevelEvents extends IPageEvents, IDomStorageEvents {
'dialog-closed': {
wasConfirmed: boolean;
userInput: string;
};
}
export default class Page extends TypedEventEmitter implements IPage {
keyboard: Keyboard;
mouse: Mouse;
workersById: Map;
readonly browserContext: BrowserContext;
readonly opener: Page | null;
networkManager: NetworkManager;
framesManager: FramesManager;
domStorageTracker: DomStorageTracker;
groupName: string;
runPageScripts: boolean;
popupInitializeFn?: (page: Page, openParams: {
url: string;
windowName: string;
}) => Promise;
devtoolsSession: DevtoolsSession;
targetId: string;
isClosed: boolean;
readonly isReady: Promise;
windowOpenParams: Protocol.Page.WindowOpenEvent;
installJsPathIntoIsolatedContext: boolean;
readonly tabId: number;
activeDialog: IDialog;
get id(): string;
get mainFrame(): Frame;
get frames(): Frame[];
get workers(): Worker[];
get lastActivityId(): number;
readonly logger: IBoundLog;
private isClosing;
private closePromise;
private readonly events;
private waitTimeouts;
constructor(devtoolsSession: DevtoolsSession, targetId: string, browserContext: BrowserContext, logger: IBoundLog, opener: Page | null, pageOptions?: IPageCreateOptions);
setNetworkRequestInterceptor(networkRequestsFn: (request: Protocol.Fetch.RequestPausedEvent) => Promise): Promise;
interact(...interactionGroups: IInteractionGroup[]): Promise;
click(jsPathOrSelector: IJsPath | string, verification?: IElementInteractVerification): Promise;
type(text: string): Promise;
addNewDocumentScript(script: string, isolatedEnvironment: boolean): Promise<{
identifier: string;
}>;
removeDocumentScript(identifier: string): Promise;
addPageCallback(name: string, onCallback?: (payload: string, frame: IFrame) => any, isolateFromWebPageEnvironment?: boolean): Promise;
setJavaScriptEnabled(enabled: boolean): Promise;
evaluate(expression: string, isolatedFromWebPageEnvironment?: boolean): Promise;
navigate(url: string, options?: {
referrer?: string;
}): Promise<{
loaderId: string;
}>;
goto(url: string, options?: {
timeoutMs?: number;
referrer?: string;
}): Promise;
waitForLoad(status: ILoadStatus, options?: IWaitForOptions): Promise;
execJsPath(jsPath: IJsPath): Promise>;
goBack(options?: {
timeoutMs?: number;
waitForLoadStatus?: LoadStatus;
}): Promise;
goForward(options?: {
timeoutMs?: number;
waitForLoadStatus?: LoadStatus;
}): Promise;
reload(options?: {
timeoutMs?: number;
}): Promise;
bringToFront(): Promise;
dismissDialog(accept: boolean, promptText?: string): Promise;
screenshot(options: IScreenshotOptions): Promise;
onWorkerAttached(devtoolsSession: DevtoolsSession, targetInfo: TargetInfo): Promise;
close(options?: {
timeoutMs?: number;
}): Promise;
onTargetKilled(errorCode: number): void;
didClose(closeError?: Error): void;
private navigateToHistory;
private initialize;
private onAttachedToTarget;
private onRuntimeException;
private onRuntimeConsole;
private onTargetCrashed;
private onWindowOpen;
private onJavascriptDialogOpening;
private onJavascriptDialogClosed;
private onMainFrameNavigated;
private onFileChooserOpened;
private onScreencastFrame;
private trimClipToSize;
private onWebsocketFrame;
}
export {};