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.waitForXPath(xpath[, options])](#pagewaitforxpathxpath-options)
* [page.workers()](#pageworkers)
- [class: Worker](#class-worker)
* [worker.evaluate(pageFunction[, ...args])](#workerevaluatepagefunction-args)
* [worker.evaluateHandle(pageFunction[, ...args])](#workerevaluatehandlepagefunction-args)
* [worker.executionContext()](#workerexecutioncontext)
* [worker.url()](#workerurl)
- [class: WebWorker](#class-webworker)
* [webWorker.evaluate(pageFunction[, ...args])](#webworkerevaluatepagefunction-args)
* [webWorker.evaluateHandle(pageFunction[, ...args])](#webworkerevaluatehandlepagefunction-args)
* [webWorker.executionContext()](#webworkerexecutioncontext)
* [webWorker.url()](#webworkerurl)
- [class: Accessibility](#class-accessibility)
* [accessibility.snapshot([options])](#accessibilitysnapshotoptions)
- [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
### 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.
```js
@ -2279,7 +2279,7 @@ for (const worker of page.workers())
console.log(' ' + worker.url());
```
#### worker.evaluate(pageFunction[, ...args])
#### webWorker.evaluate(pageFunction[, ...args])
- `pageFunction` <[function]|[string]> Function to be evaluated in the worker context
- `...args` <...[Serializable]|[JSHandle]> Arguments to pass to `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).
#### worker.evaluateHandle(pageFunction[, ...args])
#### webWorker.evaluateHandle(pageFunction[, ...args])
- `pageFunction` <[function]|[string]> Function to be evaluated in the page context
- `...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)
@ -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).
#### worker.executionContext()
#### webWorker.executionContext()
- returns: <[Promise]<[ExecutionContext]>>
#### worker.url()
#### webWorker.url()
- returns: <[string]>
### class: Accessibility
@ -3830,7 +3830,7 @@ Identifies what kind of target this is. Can be `"page"`, [`"background_page"`](h
- returns: <[string]>
#### target.worker()
- returns: <[Promise]<?[Worker]>>
- returns: <[Promise]<?[WebWorker]>>
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"
[USKeyboardLayout]: ../src/USKeyboardLayout.ts "USKeyboardLayout"
[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"
[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"

View File

@ -26,7 +26,7 @@ import { Keyboard, Mouse, Touchscreen, MouseButtonInput } from './Input';
import { Tracing } from './Tracing';
import { helper, debugError, assert } from './helper';
import { Coverage } from './Coverage';
import { Worker as PuppeteerWorker } from './Worker';
import { WebWorker } from './WebWorker';
import { Browser, BrowserContext } from './Browser';
import { Target } from './Target';
import { createJSHandle, JSHandle, ElementHandle } from './JSHandle';
@ -182,7 +182,7 @@ export class Page extends EventEmitter {
_javascriptEnabled = true;
_viewport: Viewport | null;
_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?
_fileChooserInterceptors = new Set<Function>();
@ -219,7 +219,7 @@ export class Page extends EventEmitter {
return;
}
const session = Connection.fromSession(client).session(event.sessionId);
const worker = new PuppeteerWorker(
const worker = new WebWorker(
session,
event.targetInfo.url,
this._addConsoleMessage.bind(this),
@ -409,7 +409,7 @@ export class Page extends EventEmitter {
return this._frameManager.frames();
}
workers(): PuppeteerWorker[] {
workers(): WebWorker[] {
return Array.from(this._workers.values());
}

View File

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

View File

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

View File

@ -44,5 +44,5 @@ module.exports = {
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./Input').Touchscreen,
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']),
],
[
'Worker',
'WebWorker',
new Set(['emit', 'listenerCount', 'off', 'on', 'once', 'removeListener']),
],
]);