Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: split vendor APIs #38

Merged
merged 1 commit into from
Nov 20, 2019
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- GEN:test-stats -->
|Firefox|Chromium|WebKit|all|
|---|---|---|---|
|508/634|685/692|325/637|309/634|
|508/632|683/690|325/635|309/632|
<!-- GEN:stop -->

# Contributing
Expand Down
8 changes: 0 additions & 8 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
* [event: 'console'](#event-console)
* [event: 'dialog'](#event-dialog)
* [event: 'domcontentloaded'](#event-domcontentloaded)
* [event: 'error'](#event-error)
* [event: 'frameattached'](#event-frameattached)
* [event: 'framedetached'](#event-framedetached)
* [event: 'framenavigated'](#event-framenavigated)
Expand Down Expand Up @@ -995,13 +994,6 @@ Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` o

Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.

#### event: 'error'
- <[Error]>

Emitted when the page crashes.

> **NOTE** `error` event has a special meaning in Node, see [error events](https://nodejs.org/api/events.html#events_error_events) for details.

#### event: 'frameattached'
- <[Frame]>

Expand Down
101 changes: 10 additions & 91 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,10 @@
/**
* Copyright 2019 Google Inc. All rights reserved.
* Modifications 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.
*/
export = {
Chromium: {
Accessibility: require('./chromium/features/accessibility').Accessibility,
Browser: require('./chromium/Browser').Browser,
BrowserContext: require('./chromium/BrowserContext').BrowserContext,
BrowserFetcher: require('./chromium/BrowserFetcher').BrowserFetcher,
CDPSession: require('./chromium/Connection').CDPSession,
ConsoleMessage: require('./chromium/Page').ConsoleMessage,
Coverage: require('./chromium/features/coverage').Coverage,
Dialog: require('./chromium/Dialog').Dialog,
ElementHandle: require('./chromium/JSHandle').ElementHandle,
ExecutionContext: require('./chromium/ExecutionContext').ExecutionContext,
FileChooser: require('./chromium/Page').FileChooser,
Frame: require('./chromium/Frame').Frame,
Geolocation: require('./chromium/features/geolocation').Geolocation,
JSHandle: require('./chromium/JSHandle').JSHandle,
Keyboard: require('./chromium/Input').Keyboard,
Mouse: require('./chromium/Input').Mouse,
PDF: require('./chromium/features/pdf').PDF,
Page: require('./chromium/Page').Page,
Permissions: require('./chromium/features/permissions').Permissions,
Playwright: require('./chromium/Playwright').Playwright,
Request: require('./chromium/NetworkManager').Request,
Response: require('./chromium/NetworkManager').Response,
Target: require('./chromium/Target').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./chromium/Input').Touchscreen,
Tracing: require('./chromium/features/tracing').Tracing,
Worker: require('./chromium/features/workers').Worker,
Workers: require('./chromium/features/workers').Workers,
},
Firefox: {
Accessibility: require('./firefox/features/accessibility').Accessibility,
Browser: require('./firefox/Browser').Browser,
BrowserContext: require('./firefox/Browser').BrowserContext,
BrowserFetcher: require('./firefox/BrowserFetcher').BrowserFetcher,
CDPSession: require('./firefox/Connection').CDPSession,
ConsoleMessage: require('./firefox/Page').ConsoleMessage,
Dialog: require('./firefox/Dialog').Dialog,
ElementHandle: require('./firefox/JSHandle').ElementHandle,
ExecutionContext: require('./firefox/ExecutionContext').ExecutionContext,
FileChooser: require('./firefox/Page').FileChooser,
Frame: require('./firefox/FrameManager').Frame,
JSHandle: require('./firefox/JSHandle').JSHandle,
Keyboard: require('./firefox/Input').Keyboard,
Mouse: require('./firefox/Input').Mouse,
Page: require('./firefox/Page').Page,
Permissions: require('./firefox/features/permissions').Permissions,
Playwright: require('./firefox/Playwright').Playwright,
Request: require('./firefox/NetworkManager').Request,
Response: require('./firefox/NetworkManager').Response,
Target: require('./firefox/Browser').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./firefox/Input').Touchscreen,
},
WebKit: {
Browser: require('./webkit/Browser').Browser,
BrowserContext: require('./webkit/Browser').BrowserContext,
BrowserFetcher: require('./webkit/BrowserFetcher'),
ConsoleMessage: require('./webkit/Page').ConsoleMessage,
ElementHandle: require('./webkit/JSHandle').ElementHandle,
ExecutionContext: require('./webkit/ExecutionContext').ExecutionContext,
Frame: require('./webkit/FrameManager').Frame,
JSHandle: require('./webkit/JSHandle').JSHandle,
Keyboard: require('./webkit/Input').Keyboard,
Mouse: require('./webkit/Input').Mouse,
Page: require('./webkit/Page').Page,
Playwright: require('./webkit/Playwright').Playwright,
Request: require('./webkit/NetworkManager').Request,
Response: require('./webkit/NetworkManager').Response,
Target: require('./webkit/Browser').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./webkit/Input').Touchscreen,
}
};
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import * as chromium from './chromium/api';
import * as firefox from './firefox/api';
import * as webkit from './webkit/api';

export const Chromium = chromium;
export const Firefox = firefox;
export const WebKit = webkit;
2 changes: 1 addition & 1 deletion src/chromium/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import * as childProcess from 'child_process';
import { EventEmitter } from 'events';
import { Events } from '../Events';
import { Events } from './events';
import { assert, helper } from '../helper';
import { BrowserContext } from './BrowserContext';
import { Connection, ConnectionEvents } from './Connection';
Expand Down
5 changes: 2 additions & 3 deletions src/chromium/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
* limitations under the License.
*/

import {assert} from '../helper';
import {Events} from '../Events';
import * as debug from 'debug';
import {EventEmitter} from 'events';
import { EventEmitter } from 'events';
import { ConnectionTransport } from '../ConnectionTransport';
import { assert } from '../helper';
import { Protocol } from './protocol';

const debugProtocol = debug('playwright:protocol');
Expand Down
2 changes: 1 addition & 1 deletion src/chromium/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { EventEmitter } from 'events';
import * as fs from 'fs';
import * as mime from 'mime';
import * as path from 'path';
import { Events } from '../Events';
import { Events } from './events';
import { assert, debugError, helper } from '../helper';
import { TimeoutSettings } from '../TimeoutSettings';
import { Accessibility } from './features/accessibility';
Expand Down
2 changes: 1 addition & 1 deletion src/chromium/Target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Events } from '../Events';
import { Events } from './events';
import { Browser } from './Browser';
import { BrowserContext } from './BrowserContext';
import { CDPSession } from './Connection';
Expand Down
24 changes: 24 additions & 0 deletions src/chromium/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export { TimeoutError } from '../Errors';
export { Browser } from './Browser';
export { BrowserContext } from './BrowserContext';
export { BrowserFetcher } from './BrowserFetcher';
export { CDPSession } from './Connection';
export { Dialog } from './Dialog';
export { ExecutionContext } from './ExecutionContext';
export { Accessibility } from './features/accessibility';
export { Coverage } from './features/coverage';
export { Geolocation } from './features/geolocation';
export { PDF } from './features/pdf';
export { Permissions } from './features/permissions';
export { Tracing } from './features/tracing';
export { Worker, Workers } from './features/workers';
export { Frame } from './Frame';
export { Keyboard, Mouse, Touchscreen } from './Input';
export { ElementHandle, JSHandle } from './JSHandle';
export { Request, Response } from './NetworkManager';
export { ConsoleMessage, FileChooser, Page } from './Page';
export { Playwright } from './Playwright';
export { Target } from './Target';
1 change: 0 additions & 1 deletion src/Events.ts → src/chromium/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const Events = {
Console: 'console',
Dialog: 'dialog',
DOMContentLoaded: 'domcontentloaded',
Error: 'error',
// Can't use just 'error' due to node.js special treatment of error events.
// @see https://nodejs.org/api/events.html#events_error_events
PageError: 'pageerror',
Expand Down
2 changes: 1 addition & 1 deletion src/chromium/features/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ExecutionContext } from '../ExecutionContext';
import { debugError } from '../../helper';
import { JSHandle } from '../JSHandle';
import { Protocol } from '../protocol';
import { Events } from '../../Events';
import { Events } from '../events';

type AddToConsoleCallback = (type: string, args: JSHandle[], stackTrace: Protocol.Runtime.StackTrace | undefined) => void;
type HandleExceptionCallback = (exceptionDetails: Protocol.Runtime.ExceptionDetails) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/firefox/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { EventEmitter } from 'events';
import { Events } from '../Events';
import { Events } from './events';
import { assert, helper, RegisteredListener } from '../helper';
import { Connection, ConnectionEvents } from './Connection';
import { Permissions } from './features/permissions';
Expand Down
2 changes: 1 addition & 1 deletion src/firefox/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {TimeoutSettings} from '../TimeoutSettings';
import {NavigationWatchdog} from './NavigationWatchdog';
import {Accessibility} from './features/accessibility';
import { Target, BrowserContext } from './Browser';
import { Events } from '../Events';
import { Events } from './events';

const writeFileAsync = helper.promisify(fs.writeFile);

Expand Down
16 changes: 16 additions & 0 deletions src/firefox/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export { TimeoutError } from '../Errors';
export { Browser, BrowserContext, Target } from './Browser';
export { BrowserFetcher } from './BrowserFetcher';
export { Dialog } from './Dialog';
export { ExecutionContext } from './ExecutionContext';
export { Accessibility } from './features/accessibility';
export { Permissions } from './features/permissions';
export { Frame } from './FrameManager';
export { Keyboard, Mouse, Touchscreen } from './Input';
export { ElementHandle, JSHandle } from './JSHandle';
export { Request, Response } from './NetworkManager';
export { ConsoleMessage, Page } from './Page';
export { Playwright } from './Playwright';
50 changes: 50 additions & 0 deletions src/firefox/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2019 Google Inc. All rights reserved.
* Modifications 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.
*/

export const Events = {
Page: {
Close: 'close',
Console: 'console',
Dialog: 'dialog',
DOMContentLoaded: 'domcontentloaded',
// Can't use just 'error' due to node.js special treatment of error events.
// @see https://nodejs.org/api/events.html#events_error_events
PageError: 'pageerror',
Request: 'request',
Response: 'response',
RequestFailed: 'requestfailed',
RequestFinished: 'requestfinished',
FrameAttached: 'frameattached',
FrameDetached: 'framedetached',
FrameNavigated: 'framenavigated',
Load: 'load',
Popup: 'popup',
},

Browser: {
TargetCreated: 'targetcreated',
TargetDestroyed: 'targetdestroyed',
TargetChanged: 'targetchanged',
Disconnected: 'disconnected'
},

BrowserContext: {
TargetCreated: 'targetcreated',
TargetDestroyed: 'targetdestroyed',
TargetChanged: 'targetchanged',
}
};
9 changes: 1 addition & 8 deletions src/webkit/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import * as childProcess from 'child_process';
import { EventEmitter } from 'events';
import { Connection } from './Connection';
import { Events } from '../Events';
import { Events } from './events';
import { RegisteredListener, assert, helper } from '../helper';
import { Page, Viewport } from './Page';
import { Target } from './Target';
Expand Down Expand Up @@ -157,13 +157,6 @@ export class Browser extends EventEmitter {
context = this._defaultContext;
const target = new Target(targetInfo, context);
this._targets.set(targetInfo.targetId, target);
if (target.opener() && target.opener()._pagePromise) {
const openerPage = await target.opener()._pagePromise;
if (openerPage.listenerCount(Events.Page.Popup)) {
const popupPage = await target.page();
openerPage.emit(Events.Page.Popup, popupPage);
}
}
this.emit(Events.Browser.TargetCreated, target);
context.emit(Events.BrowserContext.TargetCreated, target);
}
Expand Down
2 changes: 1 addition & 1 deletion src/webkit/FrameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as EventEmitter from 'events';
import * as fs from 'fs';
import { TimeoutError } from '../Errors';
import { Events } from '../Events';
import { Events } from './events';
import { assert, debugError, helper, RegisteredListener } from '../helper';
import { TimeoutSettings } from '../TimeoutSettings';
import { TargetSession } from './Connection';
Expand Down
2 changes: 1 addition & 1 deletion src/webkit/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { EventEmitter } from 'events';
import * as fs from 'fs';
import * as mime from 'mime';
import { TargetSession, TargetSessionEvents } from './Connection';
import { Events } from '../Events';
import { Events } from './events';
import { Frame, FrameManager, FrameManagerEvents } from './FrameManager';
import { assert, debugError, helper, RegisteredListener } from '../helper';
import { valueFromRemoteObject } from './protocolHelper';
Expand Down
8 changes: 1 addition & 7 deletions src/webkit/Target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class Target {
_targetId: string;
private _type: 'page' | 'service-worker' | 'worker';
_pagePromise: Promise<Page> | null = null;
private _openerId?: string;
private _url: string;
_initializedPromise: Promise<boolean>;
_initializedCallback: (value?: unknown) => void;
Expand All @@ -34,15 +33,14 @@ export class Target {
_isInitialized: boolean;
_eventListeners: RegisteredListener[];

constructor(targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext, openerId?: string) {
constructor(targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext) {
const {targetId, url, type} = targetInfo;
this._browserContext = browserContext;
this._targetId = targetId;
this._type = type;
/** @type {?Promise<!Page>} */
this._pagePromise = null;
this._url = url;
this._openerId = openerId;
this._isClosedPromise = new Promise(fulfill => this._closedCallback = fulfill);
if (type === 'page') {
const session = this._browserContext.browser()._connection.session(this._targetId);
Expand Down Expand Up @@ -88,8 +86,4 @@ export class Target {
browserContext(): BrowserContext {
return this._browserContext;
}

opener(): Target | null {
return this._openerId ? this.browser()._targets.get(this._openerId) : null;
}
}
13 changes: 13 additions & 0 deletions src/webkit/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export { TimeoutError } from '../Errors';
export { Browser, BrowserContext } from './Browser';
export { BrowserFetcher } from './BrowserFetcher';
export { ExecutionContext } from './ExecutionContext';
export { Frame } from './FrameManager';
export { Keyboard, Mouse } from './Input';
export { ElementHandle, JSHandle } from './JSHandle';
export { Request, Response } from './NetworkManager';
export { ConsoleMessage, Page } from './Page';
export { Playwright } from './Playwright';
Loading