chore: rename Worker to WebWorker (#5941)

To avoid TS name conflicts.
This commit is contained in:
Jack Franklin 2020-05-29 12:57:54 +01:00 committed by GitHub
parent 78624842ef
commit b874cacaef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 25 deletions

View File

@ -170,11 +170,11 @@
* [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options) * [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options)
* [page.waitForXPath(xpath[, options])](#pagewaitforxpathxpath-options) * [page.waitForXPath(xpath[, options])](#pagewaitforxpathxpath-options)
* [page.workers()](#pageworkers) * [page.workers()](#pageworkers)
- [class: Worker](#class-worker) - [class: WebWorker](#class-webworker)
* [worker.evaluate(pageFunction[, ...args])](#workerevaluatepagefunction-args) * [webWorker.evaluate(pageFunction[, ...args])](#webworkerevaluatepagefunction-args)
* [worker.evaluateHandle(pageFunction[, ...args])](#workerevaluatehandlepagefunction-args) * [webWorker.evaluateHandle(pageFunction[, ...args])](#webworkerevaluatehandlepagefunction-args)
* [worker.executionContext()](#workerexecutioncontext) * [webWorker.executionContext()](#webworkerexecutioncontext)
* [worker.url()](#workerurl) * [webWorker.url()](#webworkerurl)
- [class: Accessibility](#class-accessibility) - [class: Accessibility](#class-accessibility)
* [accessibility.snapshot([options])](#accessibilitysnapshotoptions) * [accessibility.snapshot([options])](#accessibilitysnapshotoptions)
- [class: Keyboard](#class-keyboard) - [class: Keyboard](#class-keyboard)
@ -2265,9 +2265,9 @@ This method returns all of the dedicated [WebWorkers](https://developer.mozilla.
> **NOTE** This does not contain ServiceWorkers > **NOTE** This does not contain ServiceWorkers
### class: Worker ### class: WebWorker
The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API). The WebWorker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
The events `workercreated` and `workerdestroyed` are emitted on the page object to signal the worker lifecycle. The events `workercreated` and `workerdestroyed` are emitted on the page object to signal the worker lifecycle.
```js ```js
@ -2279,7 +2279,7 @@ for (const worker of page.workers())
console.log(' ' + worker.url()); console.log(' ' + worker.url());
``` ```
#### worker.evaluate(pageFunction[, ...args]) #### webWorker.evaluate(pageFunction[, ...args])
- `pageFunction` <[function]|[string]> Function to be evaluated in the worker context - `pageFunction` <[function]|[string]> Function to be evaluated in the worker context
- `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction` - `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction`
- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` - returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction`
@ -2290,7 +2290,7 @@ If the function passed to the `worker.evaluate` returns a non-[Serializable] val
Shortcut for [(await worker.executionContext()).evaluate(pageFunction, ...args)](#executioncontextevaluatepagefunction-args). Shortcut for [(await worker.executionContext()).evaluate(pageFunction, ...args)](#executioncontextevaluatepagefunction-args).
#### worker.evaluateHandle(pageFunction[, ...args]) #### webWorker.evaluateHandle(pageFunction[, ...args])
- `pageFunction` <[function]|[string]> Function to be evaluated in the page context - `pageFunction` <[function]|[string]> Function to be evaluated in the page context
- `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction` - `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `pageFunction`
- returns: <[Promise]<[JSHandle]>> Promise which resolves to the return value of `pageFunction` as in-page object (JSHandle) - returns: <[Promise]<[JSHandle]>> Promise which resolves to the return value of `pageFunction` as in-page object (JSHandle)
@ -2301,10 +2301,10 @@ If the function passed to the `worker.evaluateHandle` returns a [Promise], then
Shortcut for [(await worker.executionContext()).evaluateHandle(pageFunction, ...args)](#executioncontextevaluatehandlepagefunction-args). Shortcut for [(await worker.executionContext()).evaluateHandle(pageFunction, ...args)](#executioncontextevaluatehandlepagefunction-args).
#### worker.executionContext() #### webWorker.executionContext()
- returns: <[Promise]<[ExecutionContext]>> - returns: <[Promise]<[ExecutionContext]>>
#### worker.url() #### webWorker.url()
- returns: <[string]> - returns: <[string]>
### class: Accessibility ### class: Accessibility
@ -3830,7 +3830,7 @@ Identifies what kind of target this is. Can be `"page"`, [`"background_page"`](h
- returns: <[string]> - returns: <[string]>
#### target.worker() #### target.worker()
- returns: <[Promise]<?[Worker]>> - returns: <[Promise]<?[WebWorker]>>
If the target is not of type `"service_worker"` or `"shared_worker"`, returns `null`. If the target is not of type `"service_worker"` or `"shared_worker"`, returns `null`.
@ -4011,7 +4011,7 @@ This method is identical to `off` and maintained for compatibility with Node's E
[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail" [UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"
[USKeyboardLayout]: ../src/USKeyboardLayout.ts "USKeyboardLayout" [USKeyboardLayout]: ../src/USKeyboardLayout.ts "USKeyboardLayout"
[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time" [UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time"
[Worker]: #class-worker "Worker" [WebWorker]: #class-worker "Worker"
[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean" [boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean"
[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function" [function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function"
[iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols "Iterator" [iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols "Iterator"

View File

@ -26,7 +26,7 @@ import { Keyboard, Mouse, Touchscreen, MouseButtonInput } from './Input';
import { Tracing } from './Tracing'; import { Tracing } from './Tracing';
import { helper, debugError, assert } from './helper'; import { helper, debugError, assert } from './helper';
import { Coverage } from './Coverage'; import { Coverage } from './Coverage';
import { Worker as PuppeteerWorker } from './Worker'; import { WebWorker } from './WebWorker';
import { Browser, BrowserContext } from './Browser'; import { Browser, BrowserContext } from './Browser';
import { Target } from './Target'; import { Target } from './Target';
import { createJSHandle, JSHandle, ElementHandle } from './JSHandle'; import { createJSHandle, JSHandle, ElementHandle } from './JSHandle';
@ -182,7 +182,7 @@ export class Page extends EventEmitter {
_javascriptEnabled = true; _javascriptEnabled = true;
_viewport: Viewport | null; _viewport: Viewport | null;
_screenshotTaskQueue: ScreenshotTaskQueue; _screenshotTaskQueue: ScreenshotTaskQueue;
_workers = new Map<string, PuppeteerWorker>(); _workers = new Map<string, WebWorker>();
// TODO: improve this typedef - it's a function that takes a file chooser or something? // TODO: improve this typedef - it's a function that takes a file chooser or something?
_fileChooserInterceptors = new Set<Function>(); _fileChooserInterceptors = new Set<Function>();
@ -219,7 +219,7 @@ export class Page extends EventEmitter {
return; return;
} }
const session = Connection.fromSession(client).session(event.sessionId); const session = Connection.fromSession(client).session(event.sessionId);
const worker = new PuppeteerWorker( const worker = new WebWorker(
session, session,
event.targetInfo.url, event.targetInfo.url,
this._addConsoleMessage.bind(this), this._addConsoleMessage.bind(this),
@ -409,7 +409,7 @@ export class Page extends EventEmitter {
return this._frameManager.frames(); return this._frameManager.frames();
} }
workers(): PuppeteerWorker[] { workers(): WebWorker[] {
return Array.from(this._workers.values()); return Array.from(this._workers.values());
} }

View File

@ -16,7 +16,7 @@
import { Events } from './Events'; import { Events } from './Events';
import { Page } from './Page'; import { Page } from './Page';
import { Worker as PuppeteerWorker } from './Worker'; import { WebWorker } from './WebWorker';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { Browser, BrowserContext } from './Browser'; import { Browser, BrowserContext } from './Browser';
import type { Viewport } from './PuppeteerViewport'; import type { Viewport } from './PuppeteerViewport';
@ -30,7 +30,7 @@ export class Target {
_ignoreHTTPSErrors: boolean; _ignoreHTTPSErrors: boolean;
_defaultViewport?: Viewport; _defaultViewport?: Viewport;
_pagePromise?: Promise<Page>; _pagePromise?: Promise<Page>;
_workerPromise?: Promise<PuppeteerWorker>; _workerPromise?: Promise<WebWorker>;
_initializedPromise: Promise<boolean>; _initializedPromise: Promise<boolean>;
_initializedCallback: (x: boolean) => void; _initializedCallback: (x: boolean) => void;
_isClosedPromise: Promise<boolean>; _isClosedPromise: Promise<boolean>;
@ -52,7 +52,7 @@ export class Target {
this._defaultViewport = defaultViewport; this._defaultViewport = defaultViewport;
/** @type {?Promise<!Puppeteer.Page>} */ /** @type {?Promise<!Puppeteer.Page>} */
this._pagePromise = null; this._pagePromise = null;
/** @type {?Promise<!PuppeteerWorker>} */ /** @type {?Promise<!WebWorker>} */
this._workerPromise = null; this._workerPromise = null;
this._initializedPromise = new Promise<boolean>( this._initializedPromise = new Promise<boolean>(
(fulfill) => (this._initializedCallback = fulfill) (fulfill) => (this._initializedCallback = fulfill)
@ -98,7 +98,7 @@ export class Target {
return this._pagePromise; return this._pagePromise;
} }
async worker(): Promise<PuppeteerWorker | null> { async worker(): Promise<WebWorker | null> {
if ( if (
this._targetInfo.type !== 'service_worker' && this._targetInfo.type !== 'service_worker' &&
this._targetInfo.type !== 'shared_worker' this._targetInfo.type !== 'shared_worker'
@ -108,7 +108,7 @@ export class Target {
// TODO(einbinder): Make workers send their console logs. // TODO(einbinder): Make workers send their console logs.
this._workerPromise = this._sessionFactory().then( this._workerPromise = this._sessionFactory().then(
(client) => (client) =>
new PuppeteerWorker( new WebWorker(
client, client,
this._targetInfo.url, this._targetInfo.url,
() => {} /* consoleAPICalled */, () => {} /* consoleAPICalled */,

View File

@ -30,7 +30,7 @@ type ExceptionThrownCallback = (
) => void; ) => void;
type JSHandleFactory = (obj: Protocol.Runtime.RemoteObject) => JSHandle; type JSHandleFactory = (obj: Protocol.Runtime.RemoteObject) => JSHandle;
export class Worker extends EventEmitter { export class WebWorker extends EventEmitter {
_client: CDPSession; _client: CDPSession;
_url: string; _url: string;
_executionContextPromise: Promise<ExecutionContext>; _executionContextPromise: Promise<ExecutionContext>;

View File

@ -44,5 +44,5 @@ module.exports = {
TimeoutError: require('./Errors').TimeoutError, TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./Input').Touchscreen, Touchscreen: require('./Input').Touchscreen,
Tracing: require('./Tracing').Tracing, Tracing: require('./Tracing').Tracing,
Worker: require('./Worker').Worker, WebWorker: require('./WebWorker').WebWorker,
}; };

View File

@ -200,7 +200,7 @@ const expectedNotFoundMethods = new Map([
new Set(['emit', 'listenerCount', 'off', 'on', 'once', 'removeListener']), new Set(['emit', 'listenerCount', 'off', 'on', 'once', 'removeListener']),
], ],
[ [
'Worker', 'WebWorker',
new Set(['emit', 'listenerCount', 'off', 'on', 'once', 'removeListener']), new Set(['emit', 'listenerCount', 'off', 'on', 'once', 'removeListener']),
], ],
]); ]);