diff --git a/docs/api.md b/docs/api.md index ec2a6789..bec45c91 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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]> +- returns: <[Promise]> 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" diff --git a/src/Page.ts b/src/Page.ts index 5c78bf4a..2e98475a 100644 --- a/src/Page.ts +++ b/src/Page.ts @@ -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(); + _workers = new Map(); // TODO: improve this typedef - it's a function that takes a file chooser or something? _fileChooserInterceptors = new Set(); @@ -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()); } diff --git a/src/Target.ts b/src/Target.ts index 7c705880..8fe0df7c 100644 --- a/src/Target.ts +++ b/src/Target.ts @@ -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; - _workerPromise?: Promise; + _workerPromise?: Promise; _initializedPromise: Promise; _initializedCallback: (x: boolean) => void; _isClosedPromise: Promise; @@ -52,7 +52,7 @@ export class Target { this._defaultViewport = defaultViewport; /** @type {?Promise} */ this._pagePromise = null; - /** @type {?Promise} */ + /** @type {?Promise} */ this._workerPromise = null; this._initializedPromise = new Promise( (fulfill) => (this._initializedCallback = fulfill) @@ -98,7 +98,7 @@ export class Target { return this._pagePromise; } - async worker(): Promise { + async worker(): Promise { 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 */, diff --git a/src/Worker.ts b/src/WebWorker.ts similarity index 98% rename from src/Worker.ts rename to src/WebWorker.ts index fd21da31..42f4a692 100644 --- a/src/Worker.ts +++ b/src/WebWorker.ts @@ -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; diff --git a/src/api.ts b/src/api.ts index 35b098b4..e9cd57f5 100644 --- a/src/api.ts +++ b/src/api.ts @@ -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, }; diff --git a/utils/doclint/check_public_api/index.js b/utils/doclint/check_public_api/index.js index 22fe64ce..6854ad61 100644 --- a/utils/doclint/check_public_api/index.js +++ b/utils/doclint/check_public_api/index.js @@ -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']), ], ]);