mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: rename DOMWorld
to IsolatedWorld
(#8761)
This commit is contained in:
parent
932a053d02
commit
837b10b15e
@ -17,7 +17,11 @@
|
||||
import {Protocol} from 'devtools-protocol';
|
||||
import {assert} from './assert.js';
|
||||
import {CDPSession} from './Connection.js';
|
||||
import {DOMWorld, PageBinding, WaitForSelectorOptions} from './DOMWorld.js';
|
||||
import {
|
||||
IsolatedWorld,
|
||||
PageBinding,
|
||||
WaitForSelectorOptions,
|
||||
} from './IsolatedWorld.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
import {JSHandle} from './JSHandle.js';
|
||||
import {InternalQueryHandler} from './QueryHandler.js';
|
||||
@ -101,19 +105,19 @@ const queryOne = async (
|
||||
};
|
||||
|
||||
const waitFor = async (
|
||||
domWorld: DOMWorld,
|
||||
isolatedWorld: IsolatedWorld,
|
||||
selector: string,
|
||||
options: WaitForSelectorOptions
|
||||
): Promise<ElementHandle<Element> | null> => {
|
||||
const binding: PageBinding = {
|
||||
name: 'ariaQuerySelector',
|
||||
pptrFunction: async (selector: string) => {
|
||||
const root = options.root || (await domWorld._document());
|
||||
const root = options.root || (await isolatedWorld._document());
|
||||
const element = await queryOne(root, selector);
|
||||
return element;
|
||||
},
|
||||
};
|
||||
return (await domWorld._waitForSelectorInPage(
|
||||
return (await isolatedWorld._waitForSelectorInPage(
|
||||
(_: Element, selector: string) => {
|
||||
return (
|
||||
globalThis as unknown as {
|
||||
@ -135,11 +139,13 @@ const queryAll = async (
|
||||
const {name, role} = parseAriaSelector(selector);
|
||||
const res = await queryAXTree(exeCtx._client, element, name, role);
|
||||
const world = exeCtx._world!;
|
||||
return (await Promise.all(
|
||||
return Promise.all(
|
||||
res.map(axNode => {
|
||||
return world.adoptBackendNode(axNode.backendDOMNodeId);
|
||||
return world.adoptBackendNode(axNode.backendDOMNodeId) as Promise<
|
||||
ElementHandle<Node>
|
||||
>;
|
||||
})
|
||||
)) as Array<ElementHandle<Node>>;
|
||||
);
|
||||
};
|
||||
|
||||
const queryAllArray = async (
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Protocol} from 'devtools-protocol';
|
||||
import {assert} from './assert.js';
|
||||
import {CDPSession} from './Connection.js';
|
||||
import {WaitForSelectorOptions} from './DOMWorld.js';
|
||||
import {WaitForSelectorOptions} from './IsolatedWorld.js';
|
||||
import {ExecutionContext} from './ExecutionContext.js';
|
||||
import {Frame, FrameManager} from './FrameManager.js';
|
||||
import {
|
||||
|
@ -17,7 +17,7 @@
|
||||
import {Protocol} from 'devtools-protocol';
|
||||
import {assert} from './assert.js';
|
||||
import {CDPSession} from './Connection.js';
|
||||
import {DOMWorld} from './DOMWorld.js';
|
||||
import {IsolatedWorld} from './IsolatedWorld.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
import {Frame} from './FrameManager.js';
|
||||
import {JSHandle} from './JSHandle.js';
|
||||
@ -57,7 +57,7 @@ export class ExecutionContext {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_world?: DOMWorld;
|
||||
_world?: IsolatedWorld;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -73,7 +73,7 @@ export class ExecutionContext {
|
||||
constructor(
|
||||
client: CDPSession,
|
||||
contextPayload: Protocol.Runtime.ExecutionContextDescription,
|
||||
world?: DOMWorld
|
||||
world?: IsolatedWorld
|
||||
) {
|
||||
this._client = client;
|
||||
this._world = world;
|
||||
|
@ -17,7 +17,7 @@
|
||||
import {Protocol} from 'devtools-protocol';
|
||||
import {assert} from './assert.js';
|
||||
import {CDPSession} from './Connection.js';
|
||||
import {DOMWorld, WaitForSelectorOptions} from './DOMWorld.js';
|
||||
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
import {EventEmitter} from './EventEmitter.js';
|
||||
import {EVALUATION_SCRIPT_URL, ExecutionContext} from './ExecutionContext.js';
|
||||
@ -530,7 +530,7 @@ export class FrameManager extends EventEmitter {
|
||||
const frameId = auxData && auxData.frameId;
|
||||
const frame =
|
||||
typeof frameId === 'string' ? this.#frames.get(frameId) : undefined;
|
||||
let world: DOMWorld | undefined;
|
||||
let world: IsolatedWorld | undefined;
|
||||
if (frame) {
|
||||
// Only care about execution contexts created for the current session.
|
||||
if (frame._client() !== session) {
|
||||
@ -763,11 +763,11 @@ export class Frame {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_mainWorld!: DOMWorld;
|
||||
_mainWorld!: IsolatedWorld;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_secondaryWorld!: DOMWorld;
|
||||
_secondaryWorld!: IsolatedWorld;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -803,13 +803,13 @@ export class Frame {
|
||||
*/
|
||||
_updateClient(client: CDPSession): void {
|
||||
this.#client = client;
|
||||
this._mainWorld = new DOMWorld(
|
||||
this._mainWorld = new IsolatedWorld(
|
||||
this.#client,
|
||||
this._frameManager,
|
||||
this,
|
||||
this._frameManager._timeoutSettings
|
||||
);
|
||||
this._secondaryWorld = new DOMWorld(
|
||||
this._secondaryWorld = new IsolatedWorld(
|
||||
this.#client,
|
||||
this._frameManager,
|
||||
this,
|
||||
|
@ -72,7 +72,7 @@ export interface PageBinding {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export class DOMWorld {
|
||||
export class IsolatedWorld {
|
||||
#frameManager: FrameManager;
|
||||
#client: CDPSession;
|
||||
#frame: Frame;
|
||||
@ -564,7 +564,7 @@ export class DOMWorld {
|
||||
// Previous operation added the binding so we are done.
|
||||
if (
|
||||
this.#ctxBindings.has(
|
||||
DOMWorld.#bindingIdentifier(name, context._contextId)
|
||||
IsolatedWorld.#bindingIdentifier(name, context._contextId)
|
||||
)
|
||||
) {
|
||||
return;
|
||||
@ -604,7 +604,7 @@ export class DOMWorld {
|
||||
}
|
||||
}
|
||||
this.#ctxBindings.add(
|
||||
DOMWorld.#bindingIdentifier(name, context._contextId)
|
||||
IsolatedWorld.#bindingIdentifier(name, context._contextId)
|
||||
);
|
||||
};
|
||||
|
||||
@ -632,7 +632,7 @@ export class DOMWorld {
|
||||
if (
|
||||
type !== 'internal' ||
|
||||
!this.#ctxBindings.has(
|
||||
DOMWorld.#bindingIdentifier(name, context._contextId)
|
||||
IsolatedWorld.#bindingIdentifier(name, context._contextId)
|
||||
)
|
||||
) {
|
||||
return;
|
||||
@ -695,7 +695,7 @@ export class DOMWorld {
|
||||
return checkWaitForOptions(node, waitForVisible, waitForHidden);
|
||||
}
|
||||
const waitTaskOptions: WaitTaskOptions = {
|
||||
domWorld: this,
|
||||
isolatedWorld: this,
|
||||
predicateBody: makePredicateString(predicate, queryOne),
|
||||
predicateAcceptsContextElement: true,
|
||||
title,
|
||||
@ -723,7 +723,7 @@ export class DOMWorld {
|
||||
const {polling = 'raf', timeout = this.#timeoutSettings.timeout()} =
|
||||
options;
|
||||
const waitTaskOptions: WaitTaskOptions = {
|
||||
domWorld: this,
|
||||
isolatedWorld: this,
|
||||
predicateBody: pageFunction,
|
||||
predicateAcceptsContextElement: false,
|
||||
title: 'function',
|
||||
@ -769,7 +769,7 @@ export class DOMWorld {
|
||||
* @internal
|
||||
*/
|
||||
export interface WaitTaskOptions {
|
||||
domWorld: DOMWorld;
|
||||
isolatedWorld: IsolatedWorld;
|
||||
predicateBody: Function | string;
|
||||
predicateAcceptsContextElement: boolean;
|
||||
title: string;
|
||||
@ -786,7 +786,7 @@ const noop = (): void => {};
|
||||
* @internal
|
||||
*/
|
||||
export class WaitTask {
|
||||
#domWorld: DOMWorld;
|
||||
#isolatedWorld: IsolatedWorld;
|
||||
#polling: 'raf' | 'mutation' | number;
|
||||
#timeout: number;
|
||||
#predicateBody: string;
|
||||
@ -824,7 +824,7 @@ export class WaitTask {
|
||||
return `return (${predicateBody})(...args);`;
|
||||
}
|
||||
|
||||
this.#domWorld = options.domWorld;
|
||||
this.#isolatedWorld = options.isolatedWorld;
|
||||
this.#polling = options.polling;
|
||||
this.#timeout = options.timeout;
|
||||
this.#root = options.root || null;
|
||||
@ -834,9 +834,9 @@ export class WaitTask {
|
||||
this.#args = options.args;
|
||||
this.#binding = options.binding;
|
||||
this.#runCount = 0;
|
||||
this.#domWorld._waitTasks.add(this);
|
||||
this.#isolatedWorld._waitTasks.add(this);
|
||||
if (this.#binding) {
|
||||
this.#domWorld._boundFunctions.set(
|
||||
this.#isolatedWorld._boundFunctions.set(
|
||||
this.#binding.name,
|
||||
this.#binding.pptrFunction
|
||||
);
|
||||
@ -868,12 +868,15 @@ export class WaitTask {
|
||||
const runCount = ++this.#runCount;
|
||||
let success: JSHandle | null = null;
|
||||
let error: Error | null = null;
|
||||
const context = await this.#domWorld.executionContext();
|
||||
const context = await this.#isolatedWorld.executionContext();
|
||||
if (this.#terminated || runCount !== this.#runCount) {
|
||||
return;
|
||||
}
|
||||
if (this.#binding) {
|
||||
await this.#domWorld._addBindingToContext(context, this.#binding.name);
|
||||
await this.#isolatedWorld._addBindingToContext(
|
||||
context,
|
||||
this.#binding.name
|
||||
);
|
||||
}
|
||||
if (this.#terminated || runCount !== this.#runCount) {
|
||||
return;
|
||||
@ -904,7 +907,7 @@ export class WaitTask {
|
||||
// throw an error - ignore this predicate run altogether.
|
||||
if (
|
||||
!error &&
|
||||
(await this.#domWorld
|
||||
(await this.#isolatedWorld
|
||||
.evaluate(s => {
|
||||
return !s;
|
||||
}, success)
|
||||
@ -922,7 +925,7 @@ export class WaitTask {
|
||||
if (error.message.includes('TypeError: binding is not a function')) {
|
||||
return this.rerun();
|
||||
}
|
||||
// When frame is detached the task should have been terminated by the DOMWorld.
|
||||
// When frame is detached the task should have been terminated by the IsolatedWorld.
|
||||
// This can fail if we were adding this task while the frame was detached,
|
||||
// so we terminate here instead.
|
||||
if (
|
||||
@ -960,7 +963,7 @@ export class WaitTask {
|
||||
|
||||
#cleanup(): void {
|
||||
this.#timeoutTimer !== undefined && clearTimeout(this.#timeoutTimer);
|
||||
this.#domWorld._waitTasks.delete(this);
|
||||
this.#isolatedWorld._waitTasks.delete(this);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import {CDPSession, CDPSessionEmittedEvents} from './Connection.js';
|
||||
import {ConsoleMessage, ConsoleMessageType} from './ConsoleMessage.js';
|
||||
import {Coverage} from './Coverage.js';
|
||||
import {Dialog} from './Dialog.js';
|
||||
import {WaitForSelectorOptions} from './DOMWorld.js';
|
||||
import {WaitForSelectorOptions} from './IsolatedWorld.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
import {EmulationManager} from './EmulationManager.js';
|
||||
import {EventEmitter, Handler} from './EventEmitter.js';
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import {ariaHandler} from './AriaQueryHandler.js';
|
||||
import {DOMWorld, WaitForSelectorOptions} from './DOMWorld.js';
|
||||
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
import {JSHandle} from './JSHandle.js';
|
||||
|
||||
@ -72,7 +72,7 @@ export interface InternalQueryHandler {
|
||||
* Akin to {@link Window.prototype.querySelectorAll}.
|
||||
*/
|
||||
waitFor?: (
|
||||
domWorld: DOMWorld,
|
||||
isolatedWorld: IsolatedWorld,
|
||||
selector: string,
|
||||
options: WaitForSelectorOptions
|
||||
) => Promise<ElementHandle<Node> | null>;
|
||||
@ -95,11 +95,11 @@ function internalizeCustomQueryHandler(
|
||||
return null;
|
||||
};
|
||||
internalHandler.waitFor = (
|
||||
domWorld: DOMWorld,
|
||||
isolatedWorld: IsolatedWorld,
|
||||
selector: string,
|
||||
options: WaitForSelectorOptions
|
||||
) => {
|
||||
return domWorld._waitForSelectorInPage(queryOne, selector, options);
|
||||
return isolatedWorld._waitForSelectorInPage(queryOne, selector, options);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@ export * from './common/Connection.js';
|
||||
export * from './common/ConnectionTransport.js';
|
||||
export * from './common/ConsoleMessage.js';
|
||||
export * from './common/Coverage.js';
|
||||
export * from './common/DOMWorld.js';
|
||||
export * from './common/Debug.js';
|
||||
export * from './common/DeviceDescriptors.js';
|
||||
export * from './common/Dialog.js';
|
||||
@ -33,6 +32,7 @@ export * from './common/FrameManager.js';
|
||||
export * from './common/HTTPRequest.js';
|
||||
export * from './common/HTTPResponse.js';
|
||||
export * from './common/Input.js';
|
||||
export * from './common/IsolatedWorld.js';
|
||||
export * from './common/JSHandle.js';
|
||||
export * from './common/LifecycleWatcher.js';
|
||||
export * from './common/NetworkConditions.js';
|
||||
|
Loading…
Reference in New Issue
Block a user